Linux Commands Part-2
11. find command
We could use the find command to locate files within a given directory.
find /home/ -name notes.txt command will search for a file called notes.txt within the home directory and its subdirectories.
find <directory-name>/ -name <filename>
To find files in the current directory use, find . -name test.txt
12. grep command
This help us to search through all the text in a given file.
grep mail app.properties -> This will search for the word mail in the app.properties file.
13. df command
df command help us to get a report on the system’s disk space usage and it will show in percentage and KBs.
If we want to see the report in megabytes, then we can use df -m
14. du(Disk Usage) command
dh command help us to check how much space a file or a directory takes. the disk usage summary will show disk block numbers instead of the usual size format.
If we want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line.
15. head command
head command help us to view the first lines of any text file. This will only show the first ten lines by default, but we have provision to change this number.
if we only want to see the first 40 lines, command is: head -n 40 config.yml.
16. tail command
A similar command as the head command, but instead of showing the first lines, the tail command will display the last ten lines of a text file.
we can modify this with tail -1000f test.log
This one has a similar function to the head command, but instead of showing the first lines, the tail command will display the last ten lines of a text file.
17. diff command
Diff command help us to find the difference between 2 given files. This will show the lines that do not match.
diff test.properties test_2.properties
18. chmod(change mode) command
This command sets the permissions of files or directories.
Syntax: chmod options permissions file name
Example: chmod +x <filename>
Suppose I want to set permission for a given file where the user can read, write, and execute it, members of your group can read and execute it, & others may only read it.
Command will look alike: chmod u=rwx,g=rx,o=r <filename>
Here u,g,o stands for "user", "group", and "other". The equals sign ("=") means "set the permissions exactly equivalent to the passed value.
The letters "r", "w", and "x" stand for "read", "write", and "execute".
octal permissions notation for the above command is chmod 754 <filename>
7, 5, and 4 digits individually represent the permissions for the user, group, and others, in sequence. Each digit is a combination of the numbers 4, 2, 1, and 0:
4 stands for "read",
2 stands for "write",
1 stands for "execute", and
0 stands for "no permission."
Now, we could say that 7 is the combination of permissions 4+2+1 (read, write, and execute for user), 5 is 4+0+1 (read, no write, and execute for groups), and 4 is 4+0+0 (read, no write, and no execute for others).
19. chown(Change Owner) command
All files are owned by a specific user in Linux. This command help us to change or transfer the ownership of a file to the given username.
chown gauravkumar test.txt will transfer the ownership of the file test.txt to gauravkumar.
20. ping command
This command help us to check connectivity status of a server. For example: ping devopswithgaurav.blogspot.com, the command will check whether you’re able to connect to devopswithgaurav and also measure the response time.






