Commands tagged Linux UNIX (21)

  • find . -type f -iname '*.flac' # searches from the current folder recursively for .flac audio files | # the output (a .flac audio files with relative path from ./ ) is piped to while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done # for each line on the list: # FILE gets the file with .flac extension and relative path # FILENAME gets FILE without the .flac extension # run flac for that FILE with output piped to lame conversion to mp3 using 192Kb bitrate Show Sample Output


    8
    find . -type f -iname '*.flac' | while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
    paulochf · 2010-08-15 19:02:19 4
  • This command can be used to extract the title defined in HTML pages


    3
    sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q' file.html
    octopus · 2010-04-19 07:41:10 5

  • 3
    rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
    octopus · 2010-04-19 07:44:49 11
  • Usage: google "[search string]" Example: google "something im searching for" This will launch firefox and execute a google search in a new tab with the provided search string. You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows: alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe' Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.


    3
    google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
    lowjax · 2013-08-01 22:21:53 21
  • Uses the shell builtin `declare` with the '-f' flag to output only functions to grep out only the function names. You can use it as an alias or function like so: alias shfunctions="builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'" shfunctions () { builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'; } Show Sample Output


    2
    builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
    sciro · 2018-07-23 05:24:04 1095

  • 1
    su - $user -c <command>
    octopus · 2010-04-16 13:17:02 4
  • Just the commands for the lvreduce I keep forgetting.


    1
    # umount /media/filesystem; e2fsck -f /dev/device ; resize2fs -p /dev/device 200G #actual newsize#;lvreduce --size 200G /dev/device; mount /media/filesystem; df -h /media/filesystem
    bbelt16ag · 2011-09-14 08:52:02 6
  • The command creates an alias called 'path', so it's useful to add it to your .profile or .bash_profile. The path command then prints the full path of any file, directory, or list of files given. Soft links will be resolved to their true location. This is especially useful if you use scp often to copy files across systems. Now rather then using pwd to get a directory, and then doing a separate cut and paste to get a file's name, you can just type 'path file' and get the full path in one operation. Show Sample Output


    1
    alias path="/usr/bin/perl -e 'use Cwd; foreach my \$file (@ARGV) {print Cwd::abs_path(\$file) .\"\n\" if(-e \$file);}'"
    espider1 · 2012-01-18 01:40:05 11
  • Lots of scripts show you how to use socat to send an email to an SMTP server; this command actually emulates an SMTP server! It assumes the client is only sending to one recipient, and it's not at all smart, but it'll capture the email into a log file and the client will stop retrying. I used this to diagnose what emails were being sent by cron and subsequently discarded, but you can use it for all sorts of things. Show Sample Output


    1
    socat TCP4-LISTEN:25,fork EXEC:'bash -c \"echo 220;sleep 1;echo 250;sleep 1;echo 250;sleep 1;echo 250;sleep 1;echo 354;sleep 1;echo 250; timeout 5 cat >> /tmp/socat.log\"'
    pfudd · 2014-11-26 21:14:05 15
  • Change open-command and type to suit your needs. One example would be to open the last .jpg file with Eye Of Gnome: eog $(ls -rt *.jpg | tail -n 1)


    0
    open-command $(ls -rt *.type | tail -n 1)
    RBerenguel · 2010-04-04 20:43:38 5
  • You can do some boolean logic like A or B then C else D using or : || and : && So you can do some : # false || false && echo true || echo false false # true || false && echo true || echo false true # false || true && echo true || echo false true # true || true && echo true || echo false true and so on ... I use it like : (ssh example.com 'test something') || $(ssh example.net 'test something') && echo ok || echo ko Show Sample Output


    0
    true || false && echo true || echo false
    Sizeof · 2010-04-20 09:17:08 5
  • Replace "Master" with desired control name (e.g. Front, Earphone, PCM, etc.). Show Sample Output


    0
    amixer -c 0 set Master 100%
    thewarden · 2013-03-28 16:30:10 5
  • The directories are created in the local host with the same structure below of a remote base directory, including the 'basedir' in case that it does not exists. You must replace user and remotehost (or IP address) with your proper values ssh will ask for the password of the user in remotehost, unless you had included properly your hostname in the remote .ssh/known_hosts file. Show Sample Output


    0
    ssh user@remotehost "find basedir -type d" | xargs -I {} -t mkdir -p {}
    neomefistox · 2013-07-17 07:14:32 13
  • dumpfile is a CSV file, which its 1st field is a phone number in format CC+10 digits Empty lines are deleted, before the output in format "prefix,ocurrences" Show Sample Output


    0
    cut -d, -f1 /var/opt/example/dumpfile.130610_subscriber.csv | cut -c3-5 | sort | uniq -c | sed -e 's/^ *//;/^$/d' | awk -F" " '{print $2 "," $1}' > SubsxPrefix.csv
    neomefistox · 2013-07-17 07:58:56 7
  • Support several arguments. Show Sample Output


    0
    google() { gg="https://www.google.com/search?q=";q="";if [[ $1 ]]; then for arg in "$@" ; do q="$q+$arg"; done ; if [[ -f /usr/bin/chromium ]]; then chromium "$gg"$q; else firefox -new-tab "$gg"$q; fi else echo 'Usage: google "[seach term]"'; fi }
    LenuX · 2013-08-08 14:34:09 8
  • Appends 4 configuration lines to your ~/.inputrc which allow you to seach history taking into account the characters you have typed so far. It is taken straight form https://help.ubuntu.com/community/UsingTheTerminal Go there for a complete description (grep for "Incremental history searching"). Not sure about the limits of this (which OS's/terminals), but probably anything unix/linux like will do. Changed my life :) Show Sample Output


    0
    echo '\n"\e[A": history-search-backward\n"\e[B": history-search-forward\n"\e[C": forward-char\n"\e[D": backward-char\n' >> ~/.inputrc
    temach · 2015-01-15 09:47:49 8
  • Set's up ETH0 to use DHCP, easy way


    0
    ifconfig eth0 0.0.0.0 0.0.0.0 && dhclient eth dhcp
    rootshadow · 2016-02-09 10:55:40 12
  • This assumes there is only one result. Either tail your search for one result or add | head -n 1 before the closing bracket. You can also use locate instead of find, if you have locate installed and updated


    -1
    evince "$(find -name 'NameOfPdf.pdf')"
    RBerenguel · 2010-04-04 20:55:51 6
  • Returns any file in the folder which would be rejected by Gmail, if you were to send zipped version. (Yes, you could just zip it and knock the extension off and put it back on the other side, but for some people this just isn't a solution) Show Sample Output


    -1
    find | egrep "\.(ade|adp|bat|chm|cmd|com|cpl|dll|exe|hta|ins|isp|jse|lib|mde|msc|msp|mst|pif|scr|sct|shb|sys|vb|vbe|vbs|vxd|wsc|wsf|wsh)$"
    poulter7 · 2010-11-23 16:53:55 11

  • -2
    /sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
    octopus · 2010-04-22 06:35:29 7
  • Ever need to erase the contents of a file and start over from scratch? This easy command allows you to do so. Be warned! This will immediately erase all the contents of your file and start you over from scratch (i.e. your file will be at 0 bytes, like if you touch a file). Show Sample Output


    -3
    > [filename]
    bbbco · 2011-05-18 14:59:02 8

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

Get notified when a job you run in a terminal is done, using NotifyOSD
This is an alias you can add to your .bashrc file to get notified when a job you run in a terminal is done. example of use sleep 20; alert Source:http://www.webupd8.org/2010/07/get-notified-when-job-you-run-in.html

Substitute audio track of video file using mencoder
Creates a new video file with video stream copied from input file and a different audio stream

Recursive find and replace file extension / suffix (mass rename files)
Find recursively all files in ~/Notes with the extension '.md' and pipe that via xargs to rename command, which will replace every '.md' to '.txt' in this example (existing files will not be overwritten).

Get free RAM in %

about how using internal separate field and store file content on variable

Fast command-line directory browsing
After typing cd directory [enter] ls [enter] so many times, I figured I'd try to make it into a function. I was surprised how smoothly I was able to integrate it into my work on the command line. Just use cdls as you would cd. It will automatically list the directory contents after you cd into the directory. To make the command always available, add it to your .bashrc file. Not quite monumental, but still pretty convenient.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

list block devices
Shows all block devices in a tree with descruptions of what they are.

Job Control
You're running a script, command, whatever.. You don't expect it to take long, now 5pm has rolled around and you're ready to go home... Wait, it's still running... You forgot to nohup it before running it... Suspend it, send it to the background, then disown it... The ouput wont go anywhere, but at least the command will still run...

reduce mp3 bitrate (and size, of course)
Useful if you have to put some mp3 files into mobile devices (ie mobile phones with no much memory)


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: