LogoDuyệtSr. Data Engineer
HomeAboutPhotosInsightsCV

Footer

Logo

Resources

  • Rust Tiếng Việt
  • /archives
  • /series
  • /tags
  • Status

me@duyet.net

  • About
  • LinkedIn
  • Resume
  • Projects

© 2026 duyet.net | Sr. Data Engineer

Shell - Mọi thao tác với tệp và thư mục trên Bash

Note: This post is over 10 years old. The information may be outdated.

Shell bash trên Linux nếu như biết khai thác thì nó sẽ là một công cụ rất mạnh, trong bài này mình sẽ liệt kê các thao tác với tệp và thư mục (copy, move, rename, zip, ...). Like a hacker :))

copy a file

Copy readme.txt vào thư mục documents

cp readme.txt documents/

duplicate a file

cp readme.txt readme.bak.txt

copy a folder

Copy thư mục myMusic vào thư mục myMedia

cp -a myMusic myMedia/
# or
cp -a myMusic/ myMedia/myMusic/

duplicate a folder

Chú ý dấu /

cp -a myMusic/ myMedia/
# or if `myMedia` folder doesn't exist
cp -a myMusic myMedia/

move a file

Di chuyển file readme.txt vào thư mục documents/

mv readme.txt documents/

Luôn sử dụng dấu / cuối thư mục, for this reason.

rename a file

Đổi tên bằng cách move nó

mv readme.txt README.md

move a folder

Tương tự di chuyển file

mv myMedia myMusic/
# or
mv myMedia/ myMusic/myMedia

rename a folder

mv myMedia/ myMusic/

create a new file

Tạo file rỗng

touch 'new file'

or

> 'new file'

create a new folder

mkdir 'untitled folder'

or

mkdir -p 'path/may/not/exist/untitled folder'

show file/folder size

stat -x readme.md

or

du -sh readme.md

open a file with the default program

Mở file trên GUI

open file       # on macOS
xdg-open file   # on Linux

zip a folder

Nén zip 1 thư mục

zip -r archive_name.zip folder_to_compress

unzip a folder

Giải nén file zip

unzip archive_name.zip

remove a file

Xóa hoàn toàn, không thể khôi phục file

rm my_useless_file

remove a folder

rm -r my_useless_folder

list folder contents

Liệt kê nội dung thư mục

ls -la my_folder

tree view a folder and its subfolders

hiển thị dưới dạng cây thư mục

tree                                                       # on Linux
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'     # on macOS

find a stale file

Tìm tất cả files modified hơn 5 ngày trước.

find my_folder -mtime +5
Jan 23, 2017·9 years ago
|Linux|
LinuxTutorialUbuntu
|Edit|
On this page
  • copy a file
  • duplicate a file
  • copy a folder
  • duplicate a folder
  • move a file
  • rename a file
  • move a folder
  • rename a folder
  • create a new file
  • create a new folder
  • show file/folder size
  • open a file with the default program
  • zip a folder
  • unzip a folder
  • remove a file
  • remove a folder
  • list folder contents
  • tree view a folder and its subfolders
  • find a stale file
On this page
  • copy a file
  • duplicate a file
  • copy a folder
  • duplicate a folder
  • move a file
  • rename a file
  • move a folder
  • rename a folder
  • create a new file
  • create a new folder
  • show file/folder size
  • open a file with the default program
  • zip a folder
  • unzip a folder
  • remove a file
  • remove a folder
  • list folder contents
  • tree view a folder and its subfolders
  • find a stale file