![]() There are a few more situations where '-' could give you grief. Tar zcf -exclude=tmp/* /some/remote/volume/backup.tg my_data_folder/ In case you haven't noticed, now exclude option includes = sign. Then, in the version below, you can delete it and run the well-formatted tar command. The latest BASH version gives you a tip - don't use a relative path use the absolute one. Therefore, command treats - as an argument start character.įortunately, it has a straightforward fix. Rm '-exclude' That is not going to happen. None of the commands below would work because rm interprets it as an argument and fails to parse it. The fun begins when you try to delete this file. It happens because the Linux kernel allows almost any character in the file and folder names, but not all commands concur. You may expect a new backup on some network device, but you create an archive ' -exclude' on your local filesystem. Let's take a look at the command below: tar zcf -exclude tmp/* /some/remote/volume/backup.tgz my_data_folder/ The Booby Trap commandĪt first glance, the command looks legit, except it does not. It adds to neverending fun because command-line warriors should memorize all kid of argument notations and formats for a score of the most common tools. System layer, user layer, core commands with the neanderthal accessory lines, modern commands, and all kinds of scripts. If you manage to find KSH or CSH nowadays, you have my respect.Īll *nix systems are similar to ogres and onions - all have layers. The commands below were tested on Red Hat Linux systems with Bash v4.x. It also doesn't have problems with file names containing quotes or apostrophes.To state the obvious. The syntax is almost indentical to xargs, except it runs in parallel. Note: a modern replacement for xargs is GNU parallel. print0 | xargs -0 -l -i echo ".png" Use GNU Parallel for xargs Use “find” on file names that may contain spaces or dash # print file names that may contain spacesįind. Xargs is a command that is used together with find to allow you to call arbitrary unix commands on list of files. The advantage of using -exec is that you can call any unix command, not just options supported by find. When you use -exec, it actually spawn process to run the shell command for each file. Using the -delete option is much faster because it doesn't spawn processes. # delete all files whose name ends with ~ # list files whose file status changed in last 60 min # list files that has been opened (accessed) in last 60 min # list files whose file content is modified in last 60 min # list files whose content have been modified within past 2 days depth -empty -type d -delete Find Recently Modified File depth -empty -type d # delete empty dirsįind. type f -empty -delete Delete empty dirs # list empty dirsįind. type f -empty # delete all empty filesįind. Delete empty files # list all empty filesįind. Make sure you test first without -delete, and make sure -delete is the last argument. (By default, directory is processed before its content.)īe very careful when using -delete. ![]() -depth means process directory's content before the directory.Delete all files, name matches a text pattern # delete all files, name ends with ~ size -9k # list files exactly 1234 bytes size +9M # list files smaller than 9 kibi bytesįind. List only files larger than n bytes # list files larger than 9 mibi bytesįind. List files whose name matches a text pattern # list files ending in.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |