Commands tagged Linux (266)

  • Have netcat listen on port 8000, point browser to http://localhost:8000/ and you see the information sent. netcat terminates as soon as your browser disconnects. I tested this command on my Fedora box but linuxrawkstar pointed out that he needs to use nc -l -p 8000 instead. This depends on the netcat version you use. The additional '-p' is required by GNU netcat that for example is used by Debian but not by the OpenBSD netcat port used by my Fedora system. Show Sample Output


    2
    nc -l 8000
    penpen · 2009-03-25 23:09:38 6
  • In the above example 'muspi merol' (the output of the first rev command) is sent to stderr and 'lorem ipsum' (the output of the second rev command) is sent to stdout. rev reverse lines of a file or files. This use of tee allows testing if a program correctly handles its input without using files that hold the data. Show Sample Output


    2
    rev <<< 'lorem ipsum' | tee /dev/stderr | rev
    penpen · 2009-03-31 13:12:09 7
  • There was another line that was dependent on having un-named screen sessions. This just wouldn't do. This one works no matter what the name is. A possible improvement would be removing the perl dependence, but that doesn't effect me.


    2
    for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
    hank · 2009-04-25 22:39:24 7
  • Shell timeout variables (TMOUT) can be very liberal about what is classified as 'activity', like having an editor open. This command string will terminate the login shell for an user with more than a day's idle time.


    2
    fuser -k `who -u | awk '$6 == "old" { print "/dev/"$2'}`
    lbonanomi · 2009-09-07 03:36:43 5
  • This command gives you the charset of a text file, which would be handy if you have no idea of the encoding. Show Sample Output


    2
    file -i <textfile>
    juvenn · 2009-09-08 01:33:19 4
  • This command will transcode a MythTV recording. The target device is a Google Nexus One mobile phone. My recordings are from a HDHomerun with Over The Air content. Plays back nicely on the N1.


    2
    ffmpeg -i /var/lib/mythtv/pretty/Chuck20100208800PMChuckVersustheMask.mpg -s 800x480 -vcodec mpeg4 -acodec libfaac -ac 2 -ar 16000 -r 13 -ab 32000 -aspect 16:9 Chuck20100208800PMChuckVersustheMask.mp4
    PLA · 2010-02-12 12:11:02 7
  • extension to tali713's random fact generator. It takes the output & sends it to notify-osd. Display time is proportional to the lengh of the fact.


    2
    wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" | while read FUNFACT; do notify-send -t $((1000+300*`echo -n $FUNFACT | wc -w`)) -i gtk-dialog-info "RandomFunFact" "$FUNFACT"; done
    mtron · 2010-04-02 09:43:32 4
  • A little aptitude magic. Note: this will remove images AND headers. If you just want to remove images: aptitude remove ?and(~i~nlinux-im ?not(~n`uname -r`)) I used this in zsh without any problems. I'm not sure how other shells will interpret some of the special characters used in the aptitude search terms. Use -s to simulate.


    2
    aptitude remove ?and(~i~nlinux-(im|he) ?not(~n`uname -r`))
    dbbolton · 2010-06-11 22:57:09 6
  • probably only works if you have one graphics card. used this: http://www.cyberciti.biz/faq/howto-find-linux-vga-video-card-ram/ as reference can be expanded, for example: lspci -v -s `lspci | awk '/VGA/{print $1}'` | sed -n '/Memory.*, prefetchable/s/.*\[size=\([^]]\+\)\]/\1/p' will just get the amount of prefetchable memory compare to: lshw -C display which does not give the size (it does give byte ranges and you could calculate the size from that, but that's a pain) Also uses a command which is not standard on linux; wheras lspci is a core utility provided by most systems Show Sample Output


    2
    lspci -v -s `lspci | awk '/VGA/{print $1}'`
    infinull · 2010-10-26 17:45:14 9
  • Specify the size in bytes using the 'c' option for the -size flag. The + sign reads as "bigger than". Then execute du on the list; sort in reverse mode and show the first 10 occurrences. Show Sample Output


    2
    find /myfs -size +209715200c -exec du -m {} \; |sort -nr |head -10
    arlequin · 2011-07-07 21:12:46 3
  • this will open a new tab in firefox for every line in a file the sleep is removable but i found that if you have a large list of urls 50+, and no sleep, it will try to open all the urls at once and this will cause them all to load a lot slower, also depending on the ram of your system sleep gives you a chance to close the tabs before they overload your ram, removing & >2/dev/null will yield unpredictable results.


    2
    for line in `cat $file`; do firefox -new-tab "$line" & 2>/dev/null; sleep 1; done
    hamsolo474 · 2011-11-12 13:47:24 3
  • Converts a number of bytes provided as input, to a human readable number. Show Sample Output


    2
    human_filesize() { awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '}
    ArtBIT · 2011-12-02 18:21:20 3
  • "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 Show Sample Output


    2
    <ctrl+r>
    *deleted* · 2012-04-15 16:42:32 5
  • list the top 15 folders by decreasing size in MB Show Sample Output


    2
    du -xB M --max-depth=2 /var | sort -rn | head -n 15
    bouktin · 2013-05-23 10:45:21 6
  • Optionally, pipe the output into http://sed.sourceforge.net/grabbag/scripts/html2iso.sed Or: wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '//,//p' | sed -n '/ Show Sample Output


    2
    wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '/<pre>/,/<\/pre>/p' | sed -n '/<table*/,/<\/table>/p' | sed '1d' | sed '$d' | recode html..ascii
    krunktron · 2013-08-17 19:42:47 9

  • 2
    grep -v rootfs /proc/mounts > /etc/mtab
    ohe · 2014-01-21 14:28:12 7
  • To show ipv6 instead, use [[ -6 ]] instead of [[ -4 ]] ip -o -6 a s | awk -F'[ /]+' '$2!~/lo/{print $4}' To show only the IP of a specific interface, in case you get more than one result: ip -o -4 a s eth0 | awk -F'[ /]+' '$2!~/lo/{print $4}' ip -o -4 a s wlan0 | awk -F'[ /]+' '$2!~/lo/{print $4}' Show Sample Output


    2
    ip -o -4 a s | awk -F'[ /]+' '$2!~/lo/{print $4}'
    paulera · 2015-02-13 11:19:31 11

  • 2
    tr '\0' ' ' </proc/21679/cmdline ; echo
    pdxdoughnut · 2015-09-25 22:08:31 16
  • Assumes you've downloaded Toni Corvera's vcs script (http://p.outlyer.net/vcs), have it in your PATH, and have installed the script's dependencies. Generates a video contact sheet of 24 thumbnails and 3 thumbnails per column. The bold font and white-on-black color scheme keeps the text readable at the chosen 70% JPEG compression quality, which keeps the file size at a manageable level. You can go even lower with the quality and get a good looking result.


    2
    vcs -c 3 -H 220 -n 24 -dt -ds -dp -j --anonymous -O bg_heading=black -O bg_sign=black -O fg_heading=white -O fg_heading=white -O fg_sign=white -O fg_title=white -O font_heading=DejaVu-Sans-Bold -O quality=70
    Negate · 2018-06-06 00:49:25 192
  • 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 977
  • explanation: grep -- displays process ids -v -- negates the matching, displays all but what is specified in the other options -u -- specifies the user to display, or in this case negate The process loops through all PIDs that are found by pgrep, then orders a forced kill to the processes in numerical order, effectively killing the parent processes first including the shells in use which will force the users to logout. Tested on Slackware Linux 12.2 and Slackware-current


    1
    for i in $(pgrep -v -u root);do kill -9 $i;done
    lostnhell · 2009-03-24 02:54:52 8
  • and, a lot uglier, with sed: ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p' Edit: Wanted to be shorter than the perl version. Still think that the perl version is the best..


    1
    ifconfig | awk -F':| +' '/ddr:/{print $4}'
    0x89 · 2009-07-25 22:51:08 4
  • The initial version of this command also outputted extra empty lines, so it went like this: 192.168.166.48 127.0.0.1 This happened on Ubuntu, i haven't tested on anything else. Show Sample Output


    1
    ifconfig | awk '/ddr:[0-9]/ {sub(/addr:/, ""); print $2}'
    danny_b85 · 2009-07-31 09:30:54 3
  • default stack size is 10M. This makes your multithread app filling rapidly your memory. on my PC I was able to create only 300thread with default stack size. Lower the default stack size to the one effectively used by your threads, let you create more. ex. putting 64k I was able to create more than 10.000threads. Obviously ...your thread shouldn't need more than 64k ram!!!


    1
    ulimit -s 64
    ioggstream · 2009-08-06 10:40:25 5
  • you must be in the directory to analyse report all files and links in the currect directory, not recursively. this find command ahs been tested on hp-ux/linux/aix/solaris. Show Sample Output


    1
    find . \( ! -name . -prune \) \( -type f -o -type l \)
    mobidyc · 2009-09-12 15:58:56 11
  • ‹ First  < 2 3 4 5 6 >  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

network interface and routing summary

Get the full path of a bash script's Git repository head.
Rather than complicated and fragile paths relative to a script like "../../other", this command will retrieve the full path of the file's repository head. Safe with spaces in directory names. Works within a symlinked directory. Broken down: $cd "$(dirname "${BASH_SOURCE[0]}")" temporarily changes directories within this expansion. Double quoted "$(dirname" and ")" with unquoted ${BASH_SOURCE[0]} allows spaces in the path. $git rev-parse --show-toplevel gets the full path of the repository head of the current working directory, which was temporarily changed by the "cd".

Define Google Chrome urpmi media source for Mandriva/Mageia (works for both 32-bit and 64-bit systems)
This command adds a urpmi media source called "google-chrome" to the urpmi configuration on Mandriva or Mageia. Needs to be run as root. We specify the option "--update" so that when Google provides a newer version of Google Chrome web browser in their download system then running a system update (eg: "urpmi --auto-update") will result in our copy of Google Chrome getting updated (along with any other Mandriva/Mageia pending updates). To install Google Chrome from this source, use: urpmi google-chrome-stable #install Google chrome web browser

Copy a file using pv and watch its progress
pv allows a user to see the progress of data through a pipeline, by giving information such as time elapsed, percentage completed (with progress bar), current throughput rate, total data transferred, and ETA. (man pv)

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"

convert strings toupper/tolower with tr

Top 10 Memory Processes (reduced output to applications and %usage only)
Top 10 Memory Processes (reduced output to applications and %usage only)

Create incremental backups of individual folders using find and tar-gzip
Problem: I wanted to backup user data individually, using and incremental method. In this example, all user data is located in "/mnt/storage/profiles", and about 25 folders inside, each with a username ( /mnt/storage/profiles/mike; /mnt/storage/profiles/lucy ...) I need each individual folder backed up, not the whole "/mnt/storage/profiles". So, using find while excluding directories depth and creating two variables (tarfile=username & desdir=destination), tar will create a .tgz file for each folder, resulting in a "mike_2013-12-05.tgz" and "lucy_2013-12-05.tgz".

Record microphone input and output to date stamped mp3 file
record audio notes or meetings requires arecord and lame run mp3gain on the resulting file to increase the volume / quality ctrl-c to stop recording

download all the presentations from UTOSC2010
miss a class at UTOSC2010? need a refresher? use this to curl down all the presentations from the UTOSC website. (http://2010.utosc.com) NOTE/WARNING this will dump them in the current directory and there are around 37 and some are big - tested on OSX10.6.1


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: