How to change the configuration with the commands pdf

Linux tail command

What exactly is happening here?

  1. The ls command lists the files in a directory.

With the '-t' option, the Files sorted by modification date. The oldest files are at the bottom of the list.

We use the search pattern '* .bak' for the data source. This is a common file extension for backup files. This also serves as a protection so that you do not accidentally delete important files when you call it up.

We pipe the file list to the Linux tail command.

  1. Using the Linux tail command without specifying any options let's read the last ten files from the list. The filenames output are the oldest files in the directory.
  2. The xargs command takes a list of files and the name of a command. The command is executed with the Pass files as arguments become.

In our example, the Linux tail command returns text with several lines. Each line contains the name of a file to be deleted. The file names are separated from the lines via 'xargs' and passed as arguments to the rm command.

  1. To delete files on Linux, we use the rm command. This deletes the files passed as arguments.

Note that the files will not be moved to the Recycle Bin, but will be deleted immediately.

Be careful when deleting files on the Linux command line. So that you can try out our example without worrying, you should first create a directory with test files. To do this, run the following code on the command line: