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

    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 0
  • This command can be used to extract the title defined in HTML pages

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

  • 3
    rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
    octopus · 2010-04-19 07:44:49 1
  • 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.

    google() { gg=""; 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 5
  • 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

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

  • 1
    su - $user -c <command>
    octopus · 2010-04-16 13:17:02 0
  • 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 'test something') || $(ssh 'test something') && echo ok || echo ko Show Sample Output

    true || false && echo true || echo false
    Sizeof · 2010-04-20 09:17:08 1
  • Just the commands for the lvreduce I keep forgetting.

    # 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 0
  • 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

    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 1
  • 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

    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 1
  • 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)

    open-command $(ls -rt *.type | tail -n 1)
    RBerenguel · 2010-04-04 20:43:38 1
  • Replace "Master" with desired control name (e.g. Front, Earphone, PCM, etc.). Show Sample Output

    amixer -c 0 set Master 100%
    thewarden · 2013-03-28 16:30:10 0
  • 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

    ssh [email protected] "find basedir -type d" | xargs -I {} -t mkdir -p {}
    neomefistox · 2013-07-17 07:14:32 0
  • 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

    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 0
  • Support several arguments. Show Sample Output

    google() { gg="";q="";if [[ $1 ]]; then for arg in "[email protected]" ; 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 0
  • 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 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

    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 0
  • Set's up ETH0 to use DHCP, easy way

    ifconfig eth0 && dhclient eth dhcp
    rootshadow · 2016-02-09 10:55:40 0
  • 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

    evince "$(find -name 'NameOfPdf.pdf')"
    RBerenguel · 2010-04-04 20:55:51 1
  • 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

    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 0

  • -2
    /sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
    octopus · 2010-04-22 06:35:29 4
  • 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

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

What's this? 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

Null a file with sudo

Show all configured ipv4
Short list of all ip. Shows even the newly supported multiple ip address on the same interface (see eth1). For ipv6 use -6

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

Count the frequency of every word for a given file
Counts the frequency of words in a file

Find all file extension in current dir.

Show what PID is listening on port 80 on Linux

Convert video files to XviD

count how many times a string appears in a (source code) tree
grep -o puts each occurrence in a separate line

Place the argument of the most recent command on the shell
This works if your terminal is in Vi mode

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

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.


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: