Bash and Linux 5 cheatsheet

Bash and Linux 5: Files and directories

9 common Bash and Linux 5 tasks.

List files with details

Long listing including hidden files, with sizes you can read.

ls -lah

Create nested directories

Create a folder and any missing parents.

mkdir -p projects/app/src

Copy a directory

Copy a folder and everything in it.

cp -r source/ backup/

Move or rename a file

Move a file, or rename it by giving a new name in the same folder.

mv old-name.txt new-name.txt

Delete a directory

Remove a folder and everything inside it, without prompting.

rm -rf build/

Caution: Deleted files do not go to a trash. Double-check the path, especially with variables or wildcards.

Create a symbolic link

Make a link to a file or folder.

ln -s /path/to/target link-name

Page through a file

Scroll a long file. Press q to quit.

less file.log

Follow a log file

Print new lines as they are added to a file.

tail -f app.log

Show the first lines

Print the first 20 lines of a file.

head -n 20 file.txt

Was this page helpful?