Linux commands

Clear screen:
clear

Change directory:
cd

Show current working directory:
pwd

List content of a directory:
ls -l

View text file:
less text_file.txt

View last lines of a text file:
tail file1 (view 10 last lines)
tail -20 file1 (view 20 last lines)

Edit text file:
vi filename
vi -r filename (recover filename that was being edited when system crashed)
:x (write and quit)
:wq (write and quit)
:q (quit)
:q! (quit and not write)
0 (move cursor to start of current line)
$ (move cursor to end of current line)
:0 (move cursor to first line in file)
:n (move to line n)
:$ (move to last line in file)
ctrl + f (move forward one screen)
ctrl + b (move backward one screen)

Copy files and directories:
cp file1 file2
cp -i file1 file2 (promt if file2 already exists)
cp file1 dir1
cp -R dir1 dir2 (create directory dir2 if not exists)

Move/rename files and directories:
mv file1 file2 (rename file1 to file2)
mv -i file1 file2 (prompt if file2 already exists)
mv file1 file2 file3 dir1 (move file1 file2 file3 to directory dir1, dir1 must exist)
mv dir1 dir2 (if dir2 does not exist, rename dir1 to dir2, else move dir1 into dir2)

Remove files and directories:
rm file1
rm -i file1 (prompt before deleting)
rm -r dir1 (delete directory dir1 and all files within)

Make directory:
mkdir dir1

Change permission:
chmod 777 file1 ([owner-owner_group-all_others],7: rwx, 6: rw-, 5: r-x, 4: r--)
chmod 777 dir1
chmod 777 dir1/*

Change file ownership:
chown some_owner file1

Becoming the superuser for a short while:
su or sudo

Becoming superuser:
su -s or sudo -s

Put program in background:
program1 &

List processes:
jobs
ps ps aux

Kill process:
kill process_id
kill -9 process_id (force to kill)

Listening ports:
sudo lsof -nP -i | grep LISTEN

Show user 's groups:
groups user1

Add user to group:
usermod -a -G group1 user1

OS version:
lsb_release -a

View cpu:
lscpu

List out information all block devices:
lsblk

Disk space of file systems:
df

Check free RAM:
free
free -m (in MegaByte)

/proc files:
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/version
cat /proc/partitions
cat /etc/*-release

Install package:
apt-get install zip (install zip package)

Create zip file:
zip zip1.zip file1 file2

Unzip file:
unzip zip1.zip
tar xzf file1.tar.gz

Copy files from a local computer to a remote computer:
scp somefile username@server:/home/username/

Copy files from a remote server to your local computer:
scp username@server:/home/username/file_name /home/local-username/file-name

Copy files from a remote server to another remote computer:
scp u1@server1:/home/u1/file_name u2@server2:/home/u2/

Sending email:
mail -s "Hello" name1@example.com
enter body text and press Ctrl + D twice
mail -a "From: user1 <user1@example.com>" -a "Reply-To:user2 <user2@example1.com>" -s "Subject 1" user3@example.com