Linux Basic Commands

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

1.

# 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

2. # file /etc/passwd -- file command tells you about file type

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

# tail -f /var/log/message -- contineuosly monitor the log files

more -- to see the content of a file in the form of pagewise


ex. # more /etc/passwd

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

5. Copy and Move the file


# cp file1 file2 -- content of file1 will copy in file2
# cp -r dir1 dir2 -- copy directory
# mv file1 file2 -- rename the file

6. System Reference manuals commands


# man
# pinfo

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

10. To check current Login User Information


# who
# w
# whoami -- to see the current login user name

11. System Command


# whereis /etc/passwd -- to see the location of any command
# tty -- to check the terminal
# last reboot -- to check the last reboot information
# uptime -- to check the system current running time

12. Network status and port checking listen or not


# netstat -ant

13. grep -- by using grep command we can search the word in pattern
# cat /etc/passwd | grep -i gaurav

14. User Administration & Group Administration


# useradd user_name -- to add the new user in system
# groupadd group_name -- to create group
# userdel -r user_name -- to remove the user with their home directory
# groupdel group_name -- to remove the group
# passwd user_name -- to give the password for user
# usermod -G group_name user_name -- to add the user in group

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

16. Access Control List (Special Permission)


# setfacl -m u:user:r /etc/docker_file -- to assign the permission at user
level
-m is the modification
u is the user name
r is the read permission to user

# setfacl -m g:grup_name:r -- to assign the permission at group level


-m is the modification
g is the group name
r is the read permission to user who belongs to that group

# getfacl /etc/docker_file -- to see the permission on docker_file

17. Archiving and compressing the File


# tar -cvf test.tar file_name
c means create a new archive
v means verbose
f menas file
test.tar is the archive name
file_name is the name of original file

# tar -xvf test.tar


x means extract the file

# bzip2 test.tar -- compress the file


output will be like test.tar.bz2

# bunzip2 test.tar.bz2 -- uncompress the file


# tar -jcvf test.tar.bz2 originalfile_name -- to archive the file with
compression at a time

# tar -jxvf test.tar.bz2 -- extract the file

Archiving and compressing the Directory

# 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

18. Copy the files between systems securely


# scp -p /etc/passwd serverX:/home/student
scp is the name of command
-p is the preserving the permission
/etc/passwd is the name of source file
serverX is the address of destinaton server, where you want to copy the file
/home/student is the actual path of destination server, where you want to send
the file

# 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

19. Backup through dump command


# yum install -y dump*
# dump 0uf /backup/full /oracle
# restore -tf full <-- to see the content of backup file
# dump 2uf /backup/1st_incremental /oracle
# dump 3uf /backup/2nd_incremental /oracle
# dump 4uf /backup/3rd_incremental /oracle

# dump 1uf /backup/differential /oracle

# restore -rf /backup/full


# restore -rf /backup/differential

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

20. Red Hat Package Manager


# rpm -q package_Name -- to check the package installed or not

21. Yellow Dog Updated Modifier


# yum install pkg_name -y -- it will take all the dependancy pkg
# yum upgrade pkg_name -- it will upgrade the pkg
# yum remove pkg_name -- to remove the pkg from system
# yum history -- will show all the yum history
# yum list pkg_name -- to see the pkg_name

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

23. To brodcast the message to all loged -in users


# wall -n "Server is going to reboot, please save your work"
this above message will distribute among all login users
this activity is userfull when patching done and you want to take reboot

24. # shutdown -r now -- immidiatly server will take reboot


# shutdown -r +15 -- server will take reboot after 15 min
# shutdown -r 23:00 -- server will take reboot at 11 pm

25. How to find all the files in /bin with specified permission 755 ?
# find /bin -perm 755 -ls

26. Lock and Unlock user account


# passwd -l username -- to lock the password
# psswdd -U username -- to unlock the password

27. # history -- will show previously typed command

28. # journalctl -- to view all message generated by the system since the last
reboot

29. # dmesg -- to check the messages related to kernel

30. # free -m -- to check the physical and virtual memory stats

31. # lsof -u user -- to list all open files by specified user

32. # lsof -i:22 -- list all network connection by port 22

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.

You might also like