Commands tagged Linux (264)

  • This will issue a shutdown command to the Windows machine. username must be an administrator on the Windows machine. Requires samba-common package installed. Other relevant commands are: net rpc shutdown -r : reboot the Windows machine net rpc abortshutdown : abort shutdown of the Windows machine Type: net rpc to show all relevant commands

    net rpc shutdown -I ipAddressOfWindowsPC -U username%password
    LrdShaper · 2009-05-31 07:18:01 8

  • 93
    lsof -i
    hank · 2009-04-25 14:24:04 7
  • This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit. A couple of variants: A little bit bigger text: watch -t -n1 "date +%T|figlet -f big" You can try other figlet fonts, too. Big sideways characters: watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)' This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here). Show Sample Output

    watch -t -n1 "date +%T|figlet"
    dennisw · 2009-06-21 01:02:37 10
  • Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages. For some reason sed gets stuck on OS X, so here's a Perl version for the Mac: curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/$2 - $1/' If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this: curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/$2 - $1/' Show Sample Output

    curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
    postrational · 2009-09-07 21:56:40 6
  • Remove security from PDF document using this very simple command on Linux and OSX. You need ghostscript for this baby to work.

    gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
    deijmaster · 2009-12-14 21:30:22 5
  • The empty file /forcefsck causes the file system check fsck to be run next time you boot up, after which it will be removed. This works too: sudo >/forcefsck

    sudo touch /forcefsck
    johnraff · 2009-10-29 17:04:47 6

  • 27
    sudo strings /dev/mem
    point_to_null · 2009-08-09 02:07:26 1
  • Instead of deleting an existing symlink and then re-creating it pointing at the new location, it is possible to perform the same action with this one command. Interesting discussion on whether this is possible to do atomically here:

    ln -nsf <TARGET> <LINK>
    rdc · 2011-07-14 14:07:06 0
  • If you are doing some tests which require reboots (e. g. startup skripts, kernel module parameters, ...), this is very time intensive, if you have got a hardware with a long pre-boot phase due to hardware checks. At this time, kexec can help, which only restarts the kernel with all related stuff. First the kernel to be started is loaded, then kexec -e jumps up to start it. Is as hard as a reboot -f, but several times faster (e. g. 1 Minute instead of 12 on some servers here). Show Sample Output

    /sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e
    olorin · 2009-08-03 07:36:49 2
  • This is useful if you have a program which doesn't work well with multicore CPUs. With taskset you can set its CPU affinity to run on only one core.

    taskset -c 0 your_command
    Alanceil · 2009-02-28 22:38:02 1
  • The `export` is unnecessary if it's only applicable to the one command.

    DISPLAY=":0.0" import -window root screenshot.png
    walterl · 2010-02-17 13:02:24 3
  • I have come across a situation in the past where someone has unlinked a file by running an 'rm' command against it while it was still being written to by a running process. The problem manifested itself when a 'df' command showed a filesystem at 100%, but this did not match the total value of a 'du -sk *'. When this happens, the process continues to write to the file but you can no longer see the file on the filesystem. Stopping and starting the process will, more often than not, get rid of the unlinked file, however this is not always possible on a live server. When you are in this situation you can use the 'lsof' command above to get the PID of the process that owns the file (in the sample output this is 23521). Run the following command to see a sym-link to the file (marked as deleted): cd /proc/23521/fd && ls -l Truncate the sym-link to regain your disk space: > /proc/23521/fd/3 I should point out that this is pretty brutal and *could* potentially destabilise your system depending on what process the file belongs to that you are truncating. Show Sample Output

    lsof +L1
    dopeman · 2010-07-14 17:21:01 2
  • Uses inotifywait from inotify-tools ( ), that is compatible only with linux. Usefull when you work with files that have to be compiled.. latex, haml, c..

    while true; do inotifywait -r -e MODIFY dir/ && make; done;
    fain182 · 2010-06-04 17:07:03 0
  • Ever needed to test firewalls but didn't have netcat, telnet or even FTP? Enter /dev/tcp, your new best friend. /dev/tcp/(hostname)/(port) is a bash builtin that bash can use to open connections to TCP and UDP ports. This one-liner opens a connection on a port to a server and lets you read and write to it from the terminal. How it works: First, exec sets up a redirect for /dev/tcp/$server/$port to file descriptor 5. Then, as per some excellent feedback from @flatcap, we launch a redirect from file descriptor 5 to STDOUT and send that to the background (which is what causes the PID to be printed when the commands are run), and then redirect STDIN to file descriptor 5 with the second cat. Finally, when the second cat dies (the connection is closed), we clean up the file descriptor with 'exec 5>&-'. It can be used to test FTP, HTTP, NTP, or can connect to netcat listening on a port (makes for a simple chat client!) Replace /tcp/ with /udp/ to use UDP instead.

    exec 5<>/dev/tcp/; cat <&5 & cat >&5; exec 5>&-
    tyzbit · 2015-07-30 21:12:38 9
  • Though without infinite time and knowledge of how the site will be designed in the future this may stop working, it still will serve as a simple straight forward starting point. This uses the observation that the only item marked as strong on the page is the single logical line that includes the italicized fact. If future revisions of the page show failure, or intermittent failure, one may simply alter the above to read. wget -O - 2>/dev/null | tee lastfact | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" The file lastfact, can then be examined whenever the command fails.

    wget -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
    tali713 · 2010-03-30 23:49:30 1
  • Very simple web server listening on port 80 will serve index.html file or whatever file you like pointing your browser at http://your-IP-address/index.html for example. If your web server is down for maintenance and you'd like to inform your visitors about it, quickly and easily, you just have to put into the index.html file the right HTML code and you are done! Of course you need to be root to run the command using port 80.

    while true ; do nc -l 80 < index.html ; done
    ztank1013 · 2011-08-31 15:17:33 6
  • This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;) Also, don't forget to add this as alias(ie alias somafm="read -p 'Which Station? "; mplayer --reallyquite -vo none -ao sdl

    read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl${REPLY}.pls
    denzuko · 2009-05-04 00:26:19 8
  • Fetches the IPs and ONLY the IPs from ifconfig. Simplest, shortest, cleanest. Perl is too good to be true... (P.S.: credit should go to Peteris Krumins at Show Sample Output

    ifconfig | perl -nle'/dr:(\S+)/ && print $1'
    xsawyerx · 2009-07-23 09:33:31 4

  • 10
    while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
    stuntdawg · 2009-03-27 08:26:39 2
  • rot13 maps (A..MN..Z) to ( and so does this alias.

    alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
    penpen · 2009-03-30 19:08:49 2

  • 10
    alias rot13="tr a-zA-Z n-za-mN-ZA-M"
    mathias · 2011-03-17 11:21:19 0
  • Produces secure passwords that satisfy most rules for secure passwords and can be customized for correct output as needed. See "man pwgen" for details. Show Sample Output

    pwgen --alt-phonics --capitalize 9 10
    CafeNinja · 2009-10-24 08:36:36 3
  • This should do the same thing and is about 70 chars shorter. Show Sample Output

    aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
    dbbolton · 2010-06-10 21:23:00 4
  • Suppose you made a backup of your hard disk with dd: dd if=/dev/sda of=/mnt/disk/backup.img This command enables you to mount a partition from inside this image, so you can access your files directly. Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img). Show Sample Output

    INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
    Alanceil · 2009-03-06 21:29:13 3
  • Let me suggest using wget for obtaining the HTTP header only as the last resort because it generates considerable textual overhead. The first ellipsis of the sample output stands for Spider mode enabled. Check if remote file exists. --2009-03-31 20:42:46-- Resolving Connecting to||:80... connected. HTTP request sent, awaiting response... and the second one looks for Length: 438 [text/html] Remote file exists and could contain further links, but recursion is disabled -- not retrieving. Show Sample Output

    wget --server-response --spider
    penpen · 2009-03-31 18:49:14 6
  •  1 2 3 >  Last ›

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

Bulk renames with find, sed and a little escaping
This command is a more flexible than my previous submission. It will work with spaces however suuuuper hacky and ugly. Source:

List files
Shortcut to list files in the current path.

Find directory depth
Returns a the directory depth.

Get the Volume labels all bitlocker volumes had before being encrypted
Get information of volume labels of bitlocker volumes, even if they are encrypted and locked (no access to filesystem, no password provided). Note that the volume labels can have spaces, but only if you name then before encryption. Renaming a bitlocker partition after being encrypted does not have the same effect as doing it before.

First pass dvd rip... The set of commands was too long, so I had to separate them into two.
This set of commands will rip a dvd title using a 2 pass mencoder xvid encode. It will provide a great quality rip. It will rip as close to 700MB as possible. (note the bitrate of -700000) Enjoy!

Yet Another Rename (bash function)
Implementation of `rename` for systems on which I don't have access to it.

Downsample mp3s to 128K
This will lower the quality of mp3 files, but is necessary to play them on some mobile devices.

intersection between two files

uniq without pre-sorting
Reads stdin, and outputs each line only once - without sorting ahead of time. This does use more memory than your system's sort utility.

List upgrade-able packages on Ubuntu
Taken from apticron and modified.

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: