Show Menu

Linux commands for beginners Cheat Sheet (DRAFT) by

A quick entry point to do some tricks on Linux.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Tree exloration

Go inside a directory
cd /a/dir­ect­roy­/name
List directory elements
ls -lrt
Print current directory
List 10 biggers direct­ories
du -sh * | sort -h | tail
Find ksh scripts containing a pattern
grep -R pattern . --include=*.ksh
Find all files older than 3 days
find . -maxdepth 1 -type f -mtime +2

Process inform­ation

List the process tree of a user
ps --forest -fu user
Check if a script is running
pgrep -af script_name

File display

Print all the content file
cat file
Print the first 20 lines
head -20 file
Print the last 30 lines
tail -30 file
Print the last lines as the file grows
tail -f file
Print the line number of a file
wc -l < file

File manipu­lation

Move a file from dir1 to dir2
mv /dir1/file /dir2/
Rename a file
mv file_name new_fi­le_name
Add execution permission for the user
chmod u+x file

File manipu­lation in row

Split one line into several lines of a fixed size
echo "abcde" | fold -c3
Union of file1 and file2
cat file1 file2
Inters­ection of file1 with file2
grep -Ff file2 file1
Exclusion of file2 from file1
grep -Fvf file2 file1

File manipu­lation in column

Append a string at each start of line
sed "­s/^­/st­art­/" file
Append a string at each end of line
sed "­s/$­/en­d/" file
Print columns 2 and 4 of a csv file
cut -d";" -f2,4 file.csv
Concat­enate two files in column
paste -d";­" file1 file2