Commands by programmer (5)

  • Create a bash script to change the modification time for each file in 'files.txt' such that they are in the same order as in 'files.txt' File name for bash script specified by variable, 'scriptName'. It is made an executable once writing into it has been completed. Show Sample Output


    1
    scriptName="reorder_files.sh"; echo -e '#!/bin/sh\n' > "${scriptName}"; cat files.txt | while read file; do echo "touch ${file}; sleep 0.5;" >> "${scriptName}"; done; chmod +x "${scriptName}";
    programmer · 2016-04-19 11:52:00 15
  • Removing Course name prefix added Show Sample Output


    1
    ls *.pdf | while read file; do newfile="${file##CS749__}"; mv "${file}" "${newfile}"; done;
    programmer · 2016-04-19 11:06:43 27
  • Adding course name prefix to lecture pdfs Show Sample Output


    1
    ls *.pdf | while read file; do newfile="CS749__${file}"; mv "${file}" "${newfile}"; done;
    programmer · 2016-04-19 11:04:47 16
  • retrieve file names back from touch commands for them Show Sample Output


    1
    touch files.txt; cat reorder_files.sh | while read line; do x=`echo $line | sed 's/touch \([a-z0-9\.]\+.*.pdf\);.*/\1/'`; echo $x >> files.txt ; done;
    programmer · 2016-04-19 11:01:17 12
  • useful to find the list of dependencies Show Sample Output


    2
    jar -tf file.jar
    programmer · 2010-10-13 10:53:07 4

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


Check These Out

Create package dependency graph
Create Debian package dependency graph using GraphViz

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Delete all files older than X in given path
This will find all files under the path "." which are older than 10 days, and delete them. If you wish to use the "rm" command instead, replace "-delete" with "-exec rm [options] {} \;"

File rotation without rename command
Rotates log files with "gz"-extension in a directory for 7 days and enumerates the number in file name. i.e.: logfile.1.gz > logfile.2.gz I needed this line due to the limitations on AIX Unix systems which do not ship with the rename command.

Rename files in batch

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

background a wget download

Run a command as root, with a delay
$ sleep 1h ; sudo command or $ sudo sleep 1h ; sudo command won't work, because by the time the delay is up, sudo will want your password again.

convert png into jpg using imagemagick

Display a list of committers sorted by the frequency of commits
Use this command to find out a list of committers sorted by the frequency of commits.


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: