Bread and Butter Commands - all important

  • This article provides practical examples of most frequently used commands in Linux/UNIX.
man - Super Important
cd ( Understand flags - dot ., double dot .., tilda~, dash -)
mkdir, mv
cp with recursive flag
ls with different flags
pwd, rm, sudo, apt
touch, cat, less, more
tail, rsync, grep
find - Super Important
sort, date, wc
tree (needs to be installed additionally)
  • man, help
#  Get help/hint about command
ls --help
man help

cd commands

  • Change directory
cd dir_1/dir_2/dir_3

# To home-directory
cd ~
cd

# To root-directory
cd /

# Back to previous dir
cd -

# One level up from the current directory 
cd ..

ls commands

  • list all files and dirs
# Excluding hidden files
ls

# Including hidden files
ls -a
# excludes . and ..
ls -A

# list the files in long format
# With an index number, owner name, group name, size, and permissions
ls -l

# without group name, owner name
ls -o
ls -g

# Print size in human-readable --> like 1K, 234M, 2G etc
ls -lh

# list all files recursively, descending down the directory tree
ls -R

# Sort the list
# by time of modification, with the newest at the top.
ls -t
# by size, with the largest at the top.
ls -S
# -lr --> reverse the sorting order
ls -lr
# long format, sorted by modification time, oldest first
ls -lrt
# Above in readable format
ls -lrth

Files commands

  • touch , cat
# Creates multiple empty file
touch file1 file2

# Create and open the file
cat > filename
# Ctrl + D --> to save and exit

# Display file content
# All
cat filename
cat < filename
# Partial
cat song.txt | more
cat song.txt | less
cat song.txt | sort


# Append at the end of the file.
cat >> filename

# Copy all data to test3
cat test test1 test2 > test3
  • cp, mv
# Copy file1 to file2
cp file1 file2

# Rename or move file1 to file2. 
mv file1 file2
  • rm
# Delete file whose name starting with a hyphen symbol (-)
rm -- -file.txt

# Force delete
# -f option will not work for write-protect directories
rm -f e.txt

Dir commands

  • mkdir, rm
# Create a dir
mkdir dir_name

# Delete empty dir
rm file_name

# Delete non-empty dir
# Remove the directory and its contents recursively
rm -r dir_name

Others

# Current dir
pwd

Reference