Linux beginners would always ask how to operate linux in terminal. Here you can see some useful commands to getting started with Linux.
Important commands linux users should learn:
Hostname [hostname] :
=> It will show the hostname of our system
Eg: [email protected]:~$ hostname
How to change hostname:
[email protected]:~$ hostname devopstree [email protected]:~$ hostname myhost [email protected]:~$ hostname myhost
How to avoid unable to resolve hostname error:
To make hostname permanent we should add new hostname in /etc/hosts file
# vim /etc/hosts change your server name in line:2 # /etc/init.d/networking restart
# hostnamectl set-hostname myhostname
=> It will display current user.
Eg, [email protected]:~$ whoami admin
=> who command used to see the total users login to the server with physical terminal TTY or PTS according to your OS.
Eg, [email protected]:/home/admin# who dinesh tty7 2016-09-19 10:09 (:0)
Pwd command :
=> It is present working directory. It will display the present directory which we are in.
Eg, [email protected]:~$ pwd /home/admin here, $ -> indicates that we are not working as root ~ -> users home directory
Cd command :
=> change directory, which is used to change our currecnt working directory.
$ cd dirctorypath
Eg, [email protected]:~$ pwd /home/admin [email protected]:~$ cd /var/local/ [email protected]:/var/local$ pwd /var/local
=> List, this is used to list the files and directories inside one directory.
Eg, [email protected]:/home$ ls admin dinesh
=> To view the files which are hidden,use “a”, brief uses are
# ls -l => long listing # ls -a => list all files including hidden files and directory # ls -lh => Size in human readable format # ll => same long listing
=> make directory, it is used to create a new directory.
Eg, [email protected]:~$ mkdir devops [email protected]:~$ ls -l total 16 drwxrwxr-x 2 admin admin 4096 Sep 19 23:00 devops
=> This is used to create a file
Eg, [email protected]:~$ touch dev [email protected]:~$ ls -l total 16 -rw-rw-r-- 1 admin admin 0 Sep 19 23:18 dev drwxrwxr-x 2 admin admin 4096 Sep 19 23:00 devops
=> This is concatenate, it is used to viewthe contents of a file. Also used to create or append contents to a file
eg, [email protected]:~$ cat > dev => give some input words
[email protected]:~$ cat dev => It will display what you gave.
[email protected]:~$ cat >> dev => used to append content in a dir
=> copy command, it uses to copy file or directory from one location to other
For file, # cp [option] location1 location 2
For dirctory # cp [option] location1 location2
eg, For file # cp /etc/hosts /var/hosts.cp For directory # cp -r /home/admin /home/dinesh/copies/ r -> recursive v -> verbose f -> force
=> move command, which is used to move content from one location to other or rename the file.
mv [option] location1 location2
eg, # mv /var/www/test.txt /var/spool/test => it will move the file
# mv /var/www/test.txt /var/www/test => it will rename the file
=> rm is used to remove files or directories from our Linux machine..
rm [option] path
eg, $ sudo rm filename $ sudo rm -r directory name
=> We should be careful when use this command especially when we are using as root. It can delete anything with force(-f).
=> this is an editor used to edit files in Linux, some other editor are vim, gedit, nano, Emacs and Lime text.
=> I will show you how to use vi/vim editor later.
Without knowing this basic commands you can never start Linux…