find . -type f -exec touch "{}" \;

touch every file in current folder and subfolder


0
By: kev
2011-06-26 03:15:55

These Might Interest You

  • if you want to replace "foo" with "bar" in all files in a folder, and put the resulting files into a new subfolder


    -5
    mkdir replaced;for i in *; do cat "$i"| sed 's/foo/bar/' > "replaced/$i"; done
    rubo77 · 2011-08-30 08:28:26 2
  • If you have a folder with thousand of files and want to have many folder with only 100 file per folder, run this. It will create 0/,1/ etc and put 100 file inside each one. But find will return true even if it don't find anything ... Show Sample Output


    -1
    folder=0;mkdir $folder; while find -maxdepth 1 -type f -exec mv "{}" $folder \; -quit ; do if [ $( ls $folder | wc -l ) -ge 100 ]; then folder=$(( $folder + 1 )); mkdir $folder; fi ; done
    Juluan · 2011-02-11 21:28:01 0
  • Will move in that case every file in the current folder older than 30 days to the "old" folder Replace "mv $i old/" by any command such as rm / echo to do something different.


    -3
    for i in $(find . -mtime +30); do mv $i old/; done
    valferon · 2014-02-05 01:24:45 1
  • This command will copy a folder tree (keeping the parent folders) through ssh. It will: - compress the data - stream the compressed data through ssh - decompress the data on the local folder This command will take no additional space on the host machine (no need to create compressed tar files, transfer it and then delete it on the host). There is some situations (like mirroring a remote machine) where you simply cant wait for a huge time taking scp command or cant compress the data to a tarball on the host because of file system space limitation, so this command can do the job quite well. This command performs very well mainly when a lot of data is involved in the process. If you copying a low amount of data, use scp instead (easier to type) Show Sample Output


    12
    ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
    polaco · 2009-11-10 20:06:47 4
  • This script will list all the files in the tarballs present on any folder or subfolder of the provided path. The while loop is for echoing the file name of the tarball before listing the files, so the tarball can be identified


    -2
    find <path> -name "*.tgz" -or -name "*.tar.gz" | while read file; do echo "$file: "; tar -tzf $file; done
    polaco · 2009-11-10 20:39:04 3
  • Choose random file from current folder. Avoids using ls.


    -2
    for i in *; do echo "$i"; done | shuf -n1
    johnraff · 2011-03-17 17:48:42 3

What Others Think

As with many "find ... exec" commands, it's quicker to use + rather than \; Your command will do "touch file1; touch file2; touch file3". This more efficient command: find . -type f -exec touch "{}" + will do "touch file1 file2 file3 ..."
flatcap · 360 weeks and 2 days ago
Similarly, I presume one could also do: find . -type f | xargs touch This should also do "touch file1 file2 file3 . . ."
ewilson · 360 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: