Most Useful Ubuntu Commands

·

4 min read

1. Open Terminal :

To open a terminal use below key board shortcut

ctrl + alt + T

2. Clear Terminal :

To clear terminal use below command

clear

3. Files / Folders:

a. create a file

touch filename

b. create a folder

mkdir foldername

c. list files / folders

ls

d. list hidden files / folders

ls -a

e. list files / folders with details such as permissions, filesize etc., .

ls -l

f. print file content on terminal.

cat filename

g. To combine two files (file1 and file2) into one file (file3):.

cat file1 file2 > file3

h. copy content of file1 to file2. (creates file2 if dosen't exist)

cp file1 file2

i. move file1 to folder1. (we can use it for both folders also)

mv file1 folder1

j. search a file for a string

grep "string to be searched" filename

k. delete a file.

rm filename

l. delete a folder (with all its sub folders).

rm -r foldername

4. Search for a process by name :

To search for a process running by name you can use the below command.

ps aux | grep "process name"

5. Search for a process by port :

To search for a process running by port you can use the below command.

lsof -i :port

6. Top Command :

It will list all the processes running with information like task, memory, cpu etc.,

top

7. User Privilege Commands :

a. run command as root (run any command as root user)

sudo

b. open a root shell

sudo -s

c. exit a root shell

exit

d. change your password

passwd

8. Firewall Commands :

a. turn on the frewall

ufw enable

b. turn of the frewall

ufw disable

c. allow all connections by default

ufw default allow

d. allow trafic on port

ufw allow port

9. Package Management Commands :

a. refresh available updates

apt-get update

b. upgrade all packages

apt-get upgrade

c. install pkg

apt-get install pkg

d. uninstall pkg

apt-get purge pkg

e. remove obsolete packages

apt-get autoremove

f. try to fix broken packages

apt-get -f install

10. Find Ip address :

To find IP address use the below command.

ifconfig