To start with, you just need to enter the command “date” to display the date and time. Display the current date and time in Linux I have included some examples below which should give you some clarity on what I explained here. Here the option is essentially a flag like -d, – debug, etc which I’ll discuss in the later section of this article.Īnd, the format lets you control the output by adding your own string and specify the values you want in the output. Here’s the syntax of the date command: date In this article, we take a look at the date command in detail and what you can do with it using some examples. Yes, you can do a couple more things using the date command like identifying a week or day from a date, calculating the time from epoch to a specified time, and a few more variations.’ temp from the /var/log/, you would use: find /var/log/ -name `*.The date command in Linux is the simplest way to display the current time and date in Linux.īut, there’s more to it than meets the eye. It is always a good idea to print the matched files before using the -delete option.įor example, to delete all files ending with. To delete all matching files, append the -delete option to the end of the match expression.Įnsure you are using this option only when you are confident that the result matches the files you want to delete. The common example would be to recursively change the website file permissions to 644 and directory permissions to 755 using the chmodĬommand: find /var/www/my_website -type d -exec chmod 0755 \ Find and Delete Files # To search for files based on their type, use the -type option and one of the following descriptors to specify the file type:įor instance, to find all directories in the current working directory Sometimes you might need to search for specific file types such as regular files, directories, or symlinks. For example, to find all files that don’t end in *.log.gz you would use: find /var/log/nginx -type f -not -name '*.log.gz' Find Files by Type # To find all files that don’t match the regex *.log.gz you can use the -not option. It is important to mention that you must either quote the pattern or escape the asterisk * symbol with backslash \ so that it doesn’t get interpreted by the shell when you use the wildcard character. log.gz inside the /var/log/nginx directory, you would type: find /var/log/nginx -type f -name '*.log.gz'
For example, to find all files ending with. Searching for files by extension is the same as searching for files by name. The command above will match “Document.pdf”, “DOCUMENT.pdf”. To run a case-insensitive search, change the -name option with -iname: find /home/linuxize -type f -iname document.pdf To find a file by its name, use the -name option followed by the name of the file you are searching for.įor example, to search for a file named document.pdf in the /home/linuxize directory, you would use the following command: find /home/linuxize -type f -name document.pdf js (JavaScript files).įinding files by name is probably the most common use of the find command. The (expression) -name "*.js tells find to search files ending with.
The /var/www (path…) specifies the directory that will be searched.
The option -L (options) tells the find command to follow symbolic links.Let’s take a look at the following example: find -L /var/www -name "*.js" To search for files in a directory, the user invoking the find command needs to have read permissions on that directory. The expression attribute is made up of options, search patterns, and actions separated by operators.attribute defines the starting directory or directories where find will search the files. The options attribute controls the treatment of the symbolic links, debugging options, and optimization method.