Linux Basic Commands
Linux Basic Commands
Linux Basic Commands
# echo $SHELL -- To know the default shell (the default shell is bash)
# echo $0 -- to know the current shell
# cat /etc/shells -- to know the available shells
3. head -- head command will show you top lines of any files
ex. # head -5 /etc/passwd -- will show you top 5 lines
tails -- tail command will show you below lines of any files
ex. # tail -5 /etc/passwd -- will show you below 5 lines
less -- to see the content of a file in the form of pagewise with support of
arrow keys (up and down)
ex. # less /etc/passwd
4. To see how many lines, words and character in a file then below command is
usefull
# wc -l /etc/passwd --l, lines
# wc -w /etc/passwd --w, words
# wc -c /etc/passwd --c, characters
7. # sosreport < need to install sos if already not installed yum inatll sos -y>
sosreport is a command in linux which collects system configuration and
daignostic information of linux os like running kernal version, loaded module.
8. Link File
# ln source_file name link_file name -- hardlink
ex. ln file1 hardfile
# ln -s original_file name link_file name -- softlink
ex. ln -s file1 softfile
9. Process Management
# top -- to see the all linux process and CPU status
# ps -ef
# kill -9 PID -- to kill the process
# df -h -- to see the partition size information in human readable format
# du -sh -- to see the perticular folders size
13. grep -- by using grep command we can search the word in pattern
# cat /etc/passwd | grep -i gaurav
15. Permission
# chmod 777 file_name
# chmod 655 file_name
# chmod 1777 directory_name -- this is the sticky bit special permission if you
want to prevent users from deleting other users files in a directory
# chown gaurav:sysadmin docker_file -- to change the owner of docker_file..
here gaurav is the file owner and sysadmin is the group
# chgrp sap docker_file -- to change the group owner of file.. here sap is the
new group assigned to docker_file
# tar -zcvf test.tar linux -- to archive the directory.. here linux is the name
of directory
# tar -zxvf test.tar -- to extract the directory
# bzip2 test.tar -- to compress the directory
# bunzip2 test.tar.bz2 -- to uncompress the directory.. here bz2 is the
extension of zip
# rsync -avz abc.tar serverX:/tmp -- when you want to send big amount of data
and tar files then use rsync because it is powerfull than scp
-a is the archive mode, rsync uses compression and decompression method while
sending ths files
Description :
We need to install dump package if want to take backup through dump
0uf means always full backup starts with 0
2uf means incremental backup starts with 1+ greater than full backup
1uf means differential backup starts with 1 less than 1st incremental l.e 1uf
because 1st incremental was 2uf
restore -tf full <-- to see the content of backup file
restore -rf full <-- to restore the backup
22. Network
# hostname -- to check the hostname
# ifconfig -- to check the ip address
# systemctl status service_name -- to check the status of service
# systemctl start service_name -- to start the service
# systemctl restart service_name -- to restart the service
# systemctl enable service_name -- to enable the service, if suppose you reboot
the server then service will come on after reboot automatically
# cat /etc/services -- to check the all port numbers of all services
25. How to find all the files in /bin with specified permission 755 ?
# find /bin -perm 755 -ls
28. # journalctl -- to view all message generated by the system since the last
reboot
33. man --> Man Stand for manual, if you want to know about any
command we use it.
35. echo --> If we want to print anything on Terminal we use echo.
36. sudo useradd Rohan --> Used to add a user
37. sudo passwd Rohan --> If we want to set password for user Rohan
38. sudo userdel Rohan --> Delete a user
39. sudo groupadd groupname --> Here we have created a group
40. sudo groupdel groupname --> Here we have deleated a group
41. cat -n filename.txt --> Adds line no to all the lines.
42. grep wordweneedtosearch filename--> Grep is used to search a specific word.
43. sort filename.txt --> It sorts the words in file alphabetically
44. chown --> Used to change the owner of file.
45. lsof --> List all the files which are open and by what process
they are open.
46. lsof -u username --> Used to list all the file that are opened by specific
user.
47. id --> It tell us all user,group id's and groups that user
belong to.
48. tar --> zip and unzip file of tar format
49. tar -cvf filename foldername--> Used to zip a file
50. tar -xvf tarfilename--> Used to unzip a file
50. cut c1-2 filename.txt-->If we need to display/select limited columns we use it
sed is texteditor--> sed 's/rohan/rahul' abc.txt-> Here s is used to search and sed
is used to replace rohan by rahul**********
51. uniq filename --> remove all duplicate lines from file
52. free --> give us info of total, free, shared, buffer memory.
53. ssh Ipaddress --> secureshell (We can get access from master to slave
node vice versa)
54. ssh-keygen --> Used to generate public and private authentication key
pair. Authentication help passwordless connection between servers
55. ip -->internet protocal , similar to ifconfig (internet
configuration)(we can see ipaddress of our machine)********ip*********
56. netstat --> Show network related information
57. nslookup google.com --> Shows DNS name gives details of domain. here domain is
google.com
58. curl --> Its used to share data to and from server using
protocal like http/ssh *************
59. cat filename.txt |tr "[a-z]" "[A-Z]" ---> Converts the text which is in
smaller case to upper case.
60. env --> shows all environment variables.
61. groups dave --> The groups command tells you which groups a user is a
member of
62. passwd -->The passwd command lets you change the password for a
user.
63. ping -->The ping command lets you verify that you have network
connectivity with 37. another network device.
64. ssh -->Use the ssh command to make a connection to a remote
Linux computer and log into 37. your account
65. uname -a --> You can obtain some system information regarding the
Linux computer you�re working on with the uname command.