Commands tagged Linux (266)

  • will purge: only installed apps: /^ii/!d avoiding current kernel stuff: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d using app names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/ avoiding stuff without a version number: /[0-9]/!d


    7
    dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
    plasticdoc · 2009-06-19 10:11:00 9
  • Remove newlines from output. One character shorter than awk /./ filename and doesn't use a superfluous cat. To be fair though, I'm pretty sure fraktil was thinking being able to nuke newlines from any command is much more useful than just from one file.


    7
    grep . filename
    TheMightyBuzzard · 2009-08-09 05:33:58 12
  • If you use Linux in a Windows domain and there are N days to expiry, this is how you can change it without resorting to a windows machine.


    7
    smbpasswd -r <domain-server> -U <user name>
    greppo · 2009-08-12 07:46:48 11
  • Will edit *.db files in the same directory with todays date. Useful for doing a mass update to domains on a nameserver, adding spf records, etc. Looks for a string starting with 200 or 201 followed by 7 numbers, and replaces with todays date. This won't overwrite Ip's but i would still do some double checking after running this. Make sure your server's date is correct, otherwise insert your own serial number. rndc reload should usually follow this command.


    7
    sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
    alf · 2010-03-24 07:28:58 10
  • Note the double space: "...^ii␣␣linux-image-2..." Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel). I'm bummed that this took 228 characters. I'd like to see a simpler version. Show Sample Output


    7
    aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
    __ · 2010-12-11 11:38:15 7
  • If you cat the file, all the parts of the command line are bunched up. If you use tr to convert the nulls to spaces, you're still left without a newline unless you add another step. This command does everything for you. Show Sample Output


    7
    xargs -0a /proc/27288/cmdline echo
    dennisw · 2015-09-25 17:35:11 17
  • The output format is given by the -printf parameter: %T@ = modify time in seconds since Jan. 1, 1970, 00:00 GMT, with fractional part. Mandatory, hidden in the end. %TY-%Tm-%Td %TH:%TM:%.2TS = modify time as YYYY-MM-DD HH:MM:SS. Optional. %p = file path Refer to http://linux.die.net/man/1/find for more about -printf formatting. ------------------------ sort -nr = sort numerically and reverse (higher values - most recent timestamp - first) head -n 5 = get only 5 first lines (change 5 to whatever you want) cut -f2- -d" " = trim first field (timestamp, used only for sorting) ------------------------ Very useful for building scripts for detecting malicious files upload and malware injections. Show Sample Output


    7
    find . -type f -printf '%T@ %TY-%Tm-%Td %TH:%TM:%.2TS %p\n' | sort -nr | head -n 5 | cut -f2- -d" "
    paulera · 2016-03-23 11:56:39 11
  • Using the grep command, retrieve all lines from any log files in /var/log/ that have one of the problem states


    6
    grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
    miketheman · 2009-06-17 19:41:04 10

  • 6
    strings /dev/mem|less
    fraktil · 2009-08-09 00:56:06 8
  • Listens for events in the directory. Each created file is displayed on stdout. Then each fileline is read by the loop and a command is run. This can be used to force permissions in a directory, as an alternative for umask. More details: http://en.positon.org/post/A-solution-to-the-umask-problem%3A-inotify-to-force-permissions


    6
    inotifywait -mrq -e CREATE --format %w%f /path/to/dir | while read FILE; do chmod g=u "$FILE"; done
    dooblem · 2010-10-21 23:36:02 4
  • Shows all configurations to apt and dpkg, rarely changed, you probably still have the default configuration. Go ahead and explore your configuration if you dare, perhaps change your apt-cache directory, Dir::Cache "var/cache/apt/"; or the names of the log files. Show Sample Output


    6
    apt-config dump
    LinuxMan · 2011-12-13 19:11:02 7
  • With this command you can get a previous or future date or time. Where can you use this? How about finding all files modified or created in the last 5 mins? touch -t `echo $(date -d "5 minute ago" "+%G%m%d%H%M.%S")` me && find . -type f -newer me List all directories created since last week? touch -t `echo $(date -d "1 week ago" "+%G%m%d%H%M.%S")` me && find . -type d -cnewer me I'm sure you can think of more ways to use it. Requires coreutils package. Show Sample Output


    5
    date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
    LrdShaper · 2009-06-01 10:41:56 9
  • or you can add "-x" to get a typical hexdump like output Show Sample Output


    5
    socat -v tcp4-l:<port> tcp4:<host>:<port>
    sitaram · 2009-09-25 17:10:16 4
  • Just after you type enter, you have 3 seconds to switch window, then "texthere" will be "typed" in the X11 application that has focus. Very useful to beat your score at games such as "How fast can you type A-Z".


    5
    sleep 3 && xdotool type --delay 0ms texthere
    drinkcat · 2010-02-18 11:44:18 19
  • Cleans all files in /tmp that have been accessed at least 2 days ago.


    5
    find /tmp -type f -atime +1 -delete
    mattoufoutu · 2010-05-11 17:08:49 5

  • 5
    while inotifywait -r -e MODIFY dir/; do make; done;
    prayer · 2010-06-08 23:34:00 6
  • Tired copy paste to get opcode from objdump huh ? Get more @ http://gunslingerc0de.wordpress.com Show Sample Output


    5
    objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
    gunslinger_ · 2010-07-11 15:44:48 110
  • Takes all .flac directories, feeds them into a simple transcode pipeline to spit out .wavs with the same name (but correct extension).


    5
    for i in *.flac; do gst-launch filesrc location="$i" ! flacdec ! wavenc ! filesink location="${i%.flac}.wav"; done
    JamesHarrison · 2010-07-17 22:48:22 5
  • Use as: $ s host1 Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN. Adapted from Hack 34 in Linux Server Hacks 2nd Addition.


    5
    s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
    salamando · 2012-09-07 23:02:52 5

  • 5
    rename 's/.xls/.ods/g' *.xls
    jedifu · 2013-09-12 13:42:56 8
  • The "proportional set size" is probably the closest representation of how much active memory a process is using in the Linux virtual memory stack. This number should also closely represent the %mem found in ps(1), htop(1), and other utilities. Show Sample Output


    5
    echo 0$(awk '/Pss/ {printf "+"$2}' /proc/$PID/smaps)|bc
    atoponce · 2013-09-26 18:20:22 10
  • This is a commodity one-liner that uses ShellCheck to assure some quality on bash and sh scripts under a specific directory. It ignores the files in .git directory. Just substitute "./.git/*" with "./.svn/*" for older and booring centralized version control. Just substitute ShellCheck with "rm" if your scripts are crap and you want to get rid of them :)


    5
    find . -type f ! -path "./.git/*" -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;
    brx75x · 2017-03-16 08:43:56 24
  • the middle command between the ; and ; is the vi commands that insert that line into the last line of the file, the esc with the carets is literally hitting the escape key, you have to have the smbfs package installed to do it, I use it to access my iTunes music on my mac from my linux PC's with amarok so I can play the music anywhere in the house. among other things, it allows you to access the files on that share from your computer anytime you're on that network.


    4
    sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
    GinoMan2440 · 2009-04-02 16:04:35 9
  • will show: installed linux headers, image, or modules: /^ii/!d avoiding current kernel: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d only application names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/ avoiding stuff without a version number: /[0-9]/!d Show Sample Output


    4
    dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
    plasticdoc · 2009-06-19 10:23:38 8
  • Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.


    4
    lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
    olorin · 2009-07-22 11:32:52 16
  •  < 1 2 3 4 >  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

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"

Rename files in batch

Download an Entire website with wget

Run a program transparently, but print a stack trace if it fails
For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn't have to mess around with core files. The one downside is that it does smoosh your program's stderr and stdout together.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

a short counter
Maybe you know shorter ?

Log colorizer for OSX (ccze alternative)
Download colorizer by @raszi @ http://github.com/raszi/colorize

Hold off any screensavers/timeouts
Moves the mouse 1 pixel down and to the right, then immediately back again, every 4 minutes. This keeps screensavers from turning on. I have used this extensively and I've never even noticed the mouse movement because it is so subtle.

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh 127.0.0.1 -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.

Get your outgoing IP address


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: