Useful Linux/Ubuntu terminal commands with example

Keywords: Linux terminal commands, basic Linux commands

 

If you are a newbi, you’ll find following Linux commands useful. These commands will work with any Linux distro.

1. To list all files and directory -> Use ls

a.) current location : ls
b.) any other location: ls <location>

$ ls
$ ls /home/

2. To change a directory -> Use cd

Syntax: cd <location>

$ cd /home/sachin/movies

3. To exit from a directory -> Use cd .. or cd \

$ cd ..
$ cd \

4. To remove a directory including all files and sub-directories in it -> Use rm -r

Syntax: rm -r <dirctory>

$ rm -r /home/sachin/movies

5. To create a new directory -> Use mkdir

Syntax: mkdir <directory location>

$mkdir /home/sachin/movies

6. To change read/write permission -> Use chmod

Syntax: sudo chmod 777 <file name>
sudo chmod -R 777 <directory name>

$ sudo chmod 777 /home/sachin/passwor.conf
$ sudo chmod -R 777 /home/sachin/movies

7. To copy a file/directoty from one location to another -> Use cp

Syntax: cp <file name that u want to copy> <location/file name where you want to copy >

$ cp /home/password.conf /home/sachin/
$ cp /home/password.conf /home/password.conf.bak

Syntax: cp <directory that you want to copy> <location where you wnt to copy>

$ cp -r /home/sachin/movies/ home/sachin/old/movies/

8. To run any command as root/super user -> Use sudo

Syntax: sudo <command>

$ sudo ls

9. To open a shell as root -> Use sudo su

$ sudo su

10. To change your password -> Use passwd

$ passwd

11. To see current date and time-> Use date

$date

12. To sync. current time with ntp server -> Use ntpdate

Syntax: sudo ntpdate <ntp-server-address>

$ sudo ntpdate ntp.ubuntu.org

13. To see/configure your ip address -> Use ifconfig

$ ifconfig

14. To see/configure wireless network -> Use iwconfig

$ iwconfig

15. To scan wirelsss network -> Use iwlist scan

$ iwlist scan

16. To bring a network interface up -> Use ip or ifconfig

a.) Using ip
Syntex:ip link set dev <interface> up

$ sudo ip link set dev eth0 up

b.) Using ifconfig
Syntex:ifconfig <interface> up

$ sudo ifconfig eth0 up

17. To bring a network interface down -> Use ip or ifconfig

a.) Using ip
Syntex:ip link set dev <interface> down

$ sudo ip link set dev eth0 down

b.) Using ifconfig
Syntex:ifconfig <interface> down

$ sudo ifconfig eth0 down

18. To see the version of ubuntu -> use lsb_release -a

$ lsb_release -a

19. To get kernel version -> Use uname -r

$ uname -r

20. To get all information about the kernel -> Use uname -a

$ uname -a

21. To update the system -> Use apt-get update

$ sudo apt-get update

22. To upgrade the system -> Use apt-get upgrade

$ sudo apt-get upgrade

23. To install a package -> Use apt-get install

Syntax: sudo apt-get install <package name>

$ sudo apt-get install rar

24. To remove a package -> Use apt-get remove

Syntax: sudo apt-get remove <package name>

$ sudo apt-get remove rar

25. To remove obsotle package automatically -> Use apt-get autoremove

$ sudo apt-get autoremove

26. To fix a package -> Use apt-get -f install

Syntax: sudo apt-get -f install <package name>

$ sudo apt-get -f install rar

27. To fix a broken package -> Use dpkg –configure -a

Syntax: sudo dpkg –configure -a <package>

$ sudo dpkg –configure -a rar

28. To istall a .deb package -> Use dpkg -i

Syntax: sudo dpkg -i pkg.deb

$ sudo dpkg -i rar.deb

29. To search for a specific string in the specified file -> Use grep

a.)Search for the given string in a single file
Syntex: grep <string pattern> <file name>

$ grep “hello” /home/sachin/helloworld.txt

b.)Checking for the given string in multiple files
Syntex: grep <string pattern> <file pattern>

$ grep “hello” /home/*.txt

A full tutorial will be update soon for more uses of grep command.

30. To see the current working directory -> Use pwd (prints only the name of current working directory, to see file and sub directories use ls)

$ pwd

Related posts

Leave a comment....