peri hokiperihokiclarustologisticsrimashaop.comangelpaintingtools.co.invrjanaenergies.comgates of olympus perihoki jadi mesin uang paling gacortrik main baccarat perihoki ala pro bikin pemula jadi jutawanpantang pulang sebelum jackpot main dadu sicbo perihokipgsoft mahjong ways 2 muncul scatter merah tiap spin perihokicara menciptakan akun perihokigacor mahjong wins 3jackpot kembar mahjong wins 3 abc1131cara menang stabil rtp mahjong ways abc1131bu nurlina menang 197 juta mahjong ways 2mahasiswa cuan 421 juta karena pola mahjongpemilik warung menang 128 juta mahjong wins 3strategi bravy erika mahjong abc1131 terungkappemuda jambi taklukkan mahjong wins 3penjual jamu menang besar mahjong wins 5pemuda kampung raup 180 juta mahjong wayskisah inspiratif petani mahjong ways keberhasilanmahasiswa menang 92 juta mahjong waysmodal warung kopi bang ojak sukses mahjong waystanpa modal maxwin mahjong wins 3 strategibocoran mahjong ways spin kombinasicara bermain mahjong untuk meraih keberuntungankeajaiban mahjong kasir indomaret sukses beli tanahmeraup keuntungan maksimal di mahjong winsid rahasia scatter hitamid pola scatterid jackpot mahjong waysid spin mahjong winsid tips jitu mahjongrahasia kemenangan mahjong ways spin slow

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Cách dùng lệnh mv trong Linux để di chuyển file và folder

Cách dùng lệnh mv trong Linux để di chuyển file và folder

Trong bài này mình sẽ hướng dẫn cách sử dụng lệnh mv trong Linux, đây là lệnh dùng để di chuyển file và folder trong hệ thống Linux.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Di chuyển file và thư mục là một trong những tác vụ cơ bản nhất mà bạn thường cần thực hiện trên hệ thống Linux. Bạn cũng có thể áp dụng cách này để đổi tên file bằng cách di chuyển và đặt cho nó một cái tên mới.

Sau đây chúng ta cùng tìm hiểu cú pháp và làm một vài ví dụ về mv command nhé.

1. Cú pháp lệnh mv trong Linux

Lệnh mv (viết tắt của move) được sử dụng để đổi tên và di chuyển các file và thư mục từ vị trí này sang vị trí khác. Cú pháp của lệnh mv như sau:

Bài viết này được đăng tại [free tuts .net]

mv [OPTIONS] SOURCE DESTINATION

Trong đó SOURCE có thể là file hoặc thư mục cần di chuyển, DESTINATION chính là nơi đến và số lượng thì tùy thuộc vào SOURCE.

  • Khi SOURCE là nhiều file hoặc thư mục thì DESTINATION phải là một thư mục. Trường hợp này thì các file hoặc folder sẽ di chuyển tới folder đích.
  • Nếu SOURCE là một file và DESTINATION là thư mục thì file đó se được chuyển đến thư mục.
  • Néu SOURCE là một file và DESTINATION cũng là một file thì bạn đang di chuyển và đổi tên file.
  • Khi SOURCE là một file và DESTINATION không tồn tại thì tức là bạn đang đổi tên của file tại ngay thư mục đang đứng. Ngược lại, nếu DESTINATION tồn tại thì là một hành động di chuyển file.

Để di chuyển một file hoặc thư mục thì bạn cần có quyền write trên cả SOURCE và DESTINATION.

Ví dụ: để di chuyển file1 từ thư mục làm việc hiện tại hiện tại sang thư mục /tmp thì bạn sẽ chạy lệnh sau:

mv file1 /tmp

Để đổi tên file thì bạn chỉ cần nhập vào file gốc và nhập tên file mới.

mv file1 file2

Cú pháp để di chuyển thư mục cũng giống như khi di chuyển file. Trong ví dụ sau, nếu thư mục dir2 tồn tại thì lệnh sẽ chuyển dir1 vào bên trong dir2. Nếu dir2 không tồn tại, dir1 sẽ được đổi tên thành dir2:

mv dir1 dir2

2. Di chuyển nhiều file và nhiều thư mục bằng lệnh mv

Để di chuyển nhiều file và thư mục thì hãy chỉ định các file mà bạn muốn di chuyển làm nguồn.

Ví dụ, để di chuyển các file file1 và file2 vào thư mục dir1 thì bạn sẽ nhập lệnh sau:

mv file1 file2 dir1

Lệnh mv cũng cho phép bạn sử dụng pattern. Ví dụ: để di chuyển tất cả các file pdf từ thư mục hiện tại sang thư mục ~/Documents thì bạn sẽ chạy lệnh sau:

mv *.pdf ~/Documents

3. Tùy chọn option trong lệnh mv Linux

Lệnh mv cho phép bạn nhập một số tùy chọn cấu hình để thực hiện di chuyển dữ liệu theo mong muốn.

Trong một số bản phân phối Linux, lệnh mv có thể là bí danh alias của lệnh mv với một option khác. Ví dụ, trong CentOS thì lệnh mv là bí danh của mv -i. Bạn có thể kiểm tra xem mv có phải là bí danh hay không bằng cách sử dụng lệnh type:

type mv

Kết quả sẽ có dạng như sau:

mv is aliased to `mv -i'

Nếu các tùy chọn xung đột thì tùy chọn cuối cùng sẽ được lấy.

Hỏi xác nhận trước khi overwrite

Theo mặc định, nếu file đích tồn tại thì nó sẽ bị ghi đè và không có một thông báo gì cho bạn biết cả. Nếu bạn muốn nhận thông báo trước khi ghi đè thì hãy thêm tùy chọn -i nhé.

mv -i file1 /tmp

Nội dung hỏi sẽ có dạng như sau:

mv: overwrite '/tmp/file1'?

Nếu bạn nhập Y và nhấn enter thì đồng ý ghi đè, nhập N và enter thì không ghi đè.

Ép buộc ghi đè

Nếu bạn cố gắng ghi đè lên file chỉ đọc thì lệnh mv sẽ nhắc bạn có muốn ghi đè lên file đó không?

mv -i file1 /tmp

mv: replace '/tmp/file1', overriding mode 0400 (r--------)? 

Để tránh bị nhắc thông báo thì bạn hãy thêm tùy chọn -f (--force):

mv -f file1 /tmp

Không ghi đè vào file đã tồn tại

Tùy chọn -n sẽ cho lệnh mv biết là không được ghi đè nếu file đã tồn tại.

mv -f file1 /tmp

nếu file 1 đã tồn tại trong thư mục /tmp thì lệnh sẽ không làm gì, ngược lại nó sẽ được di chuyển vào thư mục /tmp.

Backup file

Nếu file đích đã tồn tại thì bạn có thể tạo ra một bản backup của file đó trước khi ghi đè. Để làm điều này thì sử dụng tùy chọn -b.

mv -b file1 /tmp

Tên của file backup sẽ cùng tên với file gốc cộng với dấu ~ được thêm vào.

Xuất báo cáo kết quả

Nếu bạn muốn lệnh mv trả về một báo cáo kết quả thì hãy sử dụng tùy chọn -v nhé.

mv -v file1 /tmp

Như vậy là mình đã hướng dẫn xong cách sử dụng lệnh mv để di chuyển file và thư mục trong Linux, đây là lệnh rất hay và được sử dụng rất nhiều trong lúc quản lý hệ thống Linux.

Cùng chuyên mục:

Hướng dẫn cấu hình Mail Server trên CentOs 6.5

Hướng dẫn cấu hình Mail Server trên CentOs 6.5

Cách dùng lệnh Users trong Linux để xem user đang online

Cách dùng lệnh Users trong Linux để xem user đang online

Nếu bạn đang là quản trị viên thì việc quản lý thông tin / xem…

Cách sử dụng lệnh Wall trong Linux

Cách sử dụng lệnh Wall trong Linux

Wall là một công cụ dòng lệnh giúp hiển thị thông báo đến tất cả…

Cách dùng lệnh Whereis trong Linux

Cách dùng lệnh Whereis trong Linux

Whereis là một tiện ích dòng lệnh command line, nó cho phép bạn tìm ..

Cách sử dụng lệnh Which trong Linux

Cách sử dụng lệnh Which trong Linux

Linux dùng lệnh which để xác định vị trí file thực thi của lệnh mà…

Cách sử dụng lệnh whoami trong Linux

Cách sử dụng lệnh whoami trong Linux

Giống như tên gọi của nó, lệnh whoami in tên người dùng đang chạy ...

Cách dùng lệnh zcat trong Linux

Cách dùng lệnh zcat trong Linux

Mặc dù tính năng nén file rất hữu ích vì nó giúp ta tiết kiệm…

Hiểu rõ hơn về chmod 777 trong Linux

Hiểu rõ hơn về chmod 777 trong Linux

Bạn đang xây dựng một website và sử dụng tính năng upload ...

Cách sử dụng lệnh tail trong Linux

Cách sử dụng lệnh tail trong Linux

Mặc định thì lệnh tail sẽ hiển thị 10 dòng cuối cùng của file, thông…

Cách sử dụng lệnh Head trong Linux

Cách sử dụng lệnh Head trong Linux

Trong quá trình quản trị dữ liệu trên Linux đôi khi bạn muốn xem nhanh…

Cách sử dụng lệnh Whatis trong Linux

Cách sử dụng lệnh Whatis trong Linux

Trong bài này chúng ta sẽ tìm hiểu lệnh whatis trong ...

Cách sử dụng lệnh kill trong Linux

Cách sử dụng lệnh kill trong Linux

Linux là một hệ điều hành rất nhanh nhưng không phải lúc nào nó không…

Cách dùng lệnh who trong Linux

Cách dùng lệnh who trong Linux

Who là một công cụ dòng lệnh command-line, được ...

Cách dùng lệnh basename trong Linux

Cách dùng lệnh basename trong Linux

basename là một tiện ích dòng lệnh (command line) dùng để lấy ...

Cách sử dụng lệnh gzip trên Linux

Cách sử dụng lệnh gzip trên Linux

Gzip là một trong những thuật toán nén file phổ biến nhất, nó cho phép…

Cách dùng lệnh wait trong Linux

Cách dùng lệnh wait trong Linux

Wait là lệnh dùng để đợi một thời gian cho tới khi công việc nào…

Cách dùng lệnh ping trong Linux

Cách dùng lệnh ping trong Linux

Lệnh ping là một trong những công cụ được sử dụng nhiều nhất để khắc…

Cách dùng lệnh sleep trong Linux

Cách dùng lệnh sleep trong Linux

sleep là một tiện ích command line cho phép lập trình viên ..

Các ví dụ học Bash Script trong Linux cơ bản nhất

Các ví dụ học Bash Script trong Linux cơ bản nhất

Bash Script đuọc xem là mã code lập trình trên Linux ...

Vòng lặp until trong Shell Script

Vòng lặp until trong Shell Script

Top