The main intention of this article is to provide a basic understanding of Linux commands, you can learn more about them by using the man command man 'command name'
The following command returns the entire path for the file "names.txt" if it exists on the machine. locate "name.txt"
The following command returns all the files that has the extension ".txt" locate "*.txt"
The following command return all the files in the current working directory(.). find .
The following command return all the directories in the current working directory. find . -type d
The following command returns all the files having the file extension ".txt" in the current working directory. -type f specifies that the type that should be searched is "file". -name ".txt" specifies that the name of the file that needs to be searched is everything() with the extension .txt . find . -type f -name "*.txt"
The following command returns all the files that are modified 20 minutes ago. find . -type f -mmin -20
The following command returns all the files that has a size more than 1Kb. find . -type f -size +1k
The following command returns all the files that has got read-write-execute permissions. find . -perm 777
In the following image you can see that the file test.txt is having read and write permission for User and read permission for both Groups and Others.
The following command sets the permission to read for all the owners. chmod 444 test.txt or chmod u=r,g=r,o=r test.txt
Output :
Another Example :
The following command sets the permission to read,write and execute for User and read to both Groups and Others
chmod 744 test.txt
Output :
Example : In the following image you can see that there are 4 files and consider a situation in which we need to delete them in one go.
The following command selects all the files in the current directory("." : current directory, -type f : selects only file) and executes(-exec) the remove file command(rm -f). {} at first holds the first file file.txt then + selects the next file names.txt as + is mentioned and so on.. and for each file the command will be executed find . -type f -exec rm -f {} +
Output :
Hello and thanks for visiting! My name is Peter Johnson, and this is my website where I share intersting blogs around technology and finance.
Post Details
- Published on Jan 30, 2022