All commands (14,187)

  • I must monitorize a couple of ftp servers every morning WITHOUT a port-scanner Instead of ftp'ing on 100 ftp servers manually to test their status I use this loop. It might be adaptable to other services, however it may require a 'logout' string instead of 'quit'. The file ftps.txt contains the full list of ftp servers to monitorize.


    1
    for host in $(cat ftps.txt) ; do if echo -en "o $host 21\nquit\n" |telnet 2>/dev/null |grep -v 'Connected to' >/dev/null; then echo -en "FTP $host KO\n"; fi done
    vlan7 · 2010-01-26 15:34:18 3
  • Recursive grep through directory for file.


    -5
    find directory/ |xargs grep -i "phrase"
    tuxtutorials · 2010-01-26 14:56:56 3
  • no loop, only one call of grep, scrollable ("less is more", more or less...)


    12
    ls /usr/bin | xargs whatis | grep -v nothing | less
    michelsberg · 2010-01-26 12:59:47 31
  • Useful for Maven multimodule projects, where you want to extract all packaged jar files.


    -3
    find . -iname "*.jar" -exec cp '{}' /tmp/ \;
    unixmonkey6754 · 2010-01-26 12:19:15 3
  • This command has been used to overwrite corrupted "entries" files of a corrupted subversion working copy. Note the --files-from input format.


    3
    rsync -vd --files-from=<(find . -name entries -print ) . ../target_directory
    samyboy · 2010-01-26 09:41:12 6
  • This command toggles the touchpad on and off, when it's on, the right side scroll strip (annoying) and the tap-clicking are disabled, you can change this by changing occurances of 2 in the command to 0. this whole command can then be given a keyboard shortcut so that the touchpad is disableable without using a special fn key (which linux doesn't recognize on some computers) or a seperate button.


    -3
    if [ $(synclient -l | grep TouchpadOff | awk '{print $3}') = "2" ]; then synclient TouchpadOff=1; elif [ $(synclient -l | grep TouchpadOff | awk '{print $3}') == "1" ]; then synclient TouchpadOff=2; else synclient TouchpadOff=2; fi
    GinoMan2440 · 2010-01-26 07:52:55 5

  • 1
    find . -maxdepth 1 -type d -exec 'mv "{}" "{}-old" && svnadmin create "{}" && svnadmin recover "{}-old" && svnadmin dump "{}-old" | svnadmin load "{}" && rm -rf "{}-old"' \;
    raspi · 2010-01-26 07:06:43 3

  • 7
    for i in $(ls /usr/bin); do whatis $i | grep -v nothing; done | more
    Abiden · 2010-01-26 06:15:54 6

  • -2
    7za x \*.zip
    andrew112358 · 2010-01-25 21:50:15 2
  • Traditionally we rewind a tape using this syntaxis: mt -f /dev/rmt/0cbn rewind Redirecting the dispositive to nothing as shown above is faster. Less typing is always better.


    2
    < /dev/rmt/0cbn
    vlan7 · 2010-01-25 20:32:38 3

  • -1
    find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
    foremire · 2010-01-25 20:21:01 11
  • for example if you did a: ls -la /bin/ls then ls !$ is equivalent to doing a ls /bin/ls


    9
    !$
    ringlerun · 2010-01-24 17:59:52 22
  • running top command in batch mode. it is usefull if you want to redirect the output in a file. Show Sample Output


    2
    top -b -n 1
    r00t4u · 2010-01-24 16:17:30 5

  • 0
    dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P
    kayowas · 2010-01-24 14:23:37 4
  • Use find's built-in ability to call programs. Alternatively, find -maxdepth 1 -type f -name "*.7z" -print0 | xargx -0 -n 1 7zr e would work, too.


    -1
    find -maxdepth 1 -type f -name "*.7z" -exec 7zr e '{}' ';'
    minnmass · 2010-01-23 19:50:10 4

  • 0
    find . -type f -exec stat \{\} \; | grep Modify: | awk '{a[$2]++}END{for(i in a){print i " : " a[i] }}' | sort
    pepin · 2010-01-23 07:55:16 6
  • Restores the keyboard so your partner who expects the keys to correspond to what they're labelled can type (in qwerty).


    -2
    setxkbmap us
    keturn · 2010-01-23 04:08:46 4
  • What to type to fix the keyboard when it's all qwerty and/or the modifier key to the left of the 'a' is doing something unexpected. In addition, I've also been known to use the altwin:meta_win and compose:ralt flags.


    0
    setxkbmap dvorak '' ctrl:nocaps
    keturn · 2010-01-23 04:04:59 3
  • A command to post a message to Twitter that includes your geo-location and a short URL. The link shortening service is provide by TinyURL, the geo-location service is provided by HostIP and the IP address lookup service is provided by AppSpot. This is an upgrade of an of one of my previous contributions: http://tinyurl.com/yd2xtzv.


    4
    curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s tinyurl.com/api-create.php?url=URL_GOES_HERE) $(curl -s api.hostip.info/get_html.php?ip=$(curl ip.appspot.com))" -d source="cURL" twitter.com/statuses/update.json -o /dev/null
    o0110o · 2010-01-23 02:21:57 10

  • -7
    scp /home/svnlabs.txt root@92.178.0.56:/home/
    bakhru · 2010-01-22 21:19:37 5

  • 10
    nmap -T4 -sP 192.168.2.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
    wincus · 2010-01-22 20:36:43 7

  • 3
    for file in *.7z; do 7zr e "$file"; done
    jmcantrell · 2010-01-22 18:42:20 11
  • Connect EC2 server with public keys "/root/.ec2/id_rsa-gsg-keypair" or "/root/.ec2/keypair.pem"


    -2
    rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
    lalit241 · 2010-01-22 17:21:58 3
  • Upload file to remote server using SCP


    -9
    scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
    lalit241 · 2010-01-22 17:21:07 3
  • Upload file to remote server using SCP


    -6
    scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
    svnlabs · 2010-01-22 16:55:25 4
  • ‹ First  < 406 407 408 409 410 >  Last ›

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

Replicate a directory structure dropping the files

find out how many days since given date
You can also do this for seconds, minutes, hours, etc... Can't use dates before the epoch, though.

Count number of files in subdirectories
For each directory from the current one, list the counts of files in each of these directories. Change the -maxdepth to drill down further through directories.

Adequately order the page numbers to print a booklet
Useful if you don't have at hand the ability to automatically create a booklet, but still want to. F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed. In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en : 1) Click File ▸ Print. 2) Choose the General tab. Under Range, choose Pages. Type the numbers of the pages in this order (this is what this one-liner does for you): n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11... ...until you have typed n-number of pages. 3) Choose the Page Setup tab. - Assuming a duplex printer: Under Layout, in the Two-side menu, select Short Edge (Flip). - If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages. In the Pages per side option, select 2. In the Page ordering menu, select Left to right. 4) Click Print.

Sort files by date
Show you the list of files of current directory sorted by date youngest to oldest, remove the 'r' if you want it in the otherway.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

reverse-i-search: Search through your command line history
"What it actually shows is going to be dependent on the commands you've previously entered. When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it). If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental. Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

Get the list of local files that changed since their last upload in an S3 bucket
Can be useful to granulary flush files in a CDN after they've been changed in the S3 bucket.

print DateTimeOriginal from EXIF data for all files in folder
see output from `identify -verbose` for other keywords to filter for (e.g. date:create, exif:DateTime, EXIF:ExifOffset).

Change every instance of OLD to NEW in file FILE
Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)


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: