Commands using head (314)

  • Get an approximation of who the workstation is assigned to. You can wrap it in su - "$()" if you want to log into a shell as that user. Show Sample Output


    0
    last | grep -i console | grep -iv 'root' | cut -f 1 -d ' ' | sort | uniq -c | sort -nr | awk '{print $2}' | head -1
    phyxia · 2015-07-20 18:07:40 10
  • Useful when you need to generate password or random hash string. If you need longer string adjust parameter for "head -c 20" Show Sample Output


    0
    dd if=/dev/urandom bs=1k count=1 2>/dev/null|LC_CTYPE=C tr -dc 'abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'|head -c 20
    nitrogear · 2015-07-25 21:24:28 9

  • 0
    ls -1 /proc/$(ps ax | grep <Process Name> | head -n 1 | awk '{print $1;}')/task | tail -n +2
    happymarmoset · 2015-10-06 07:44:48 10

  • 0
    cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30
    kenorb · 2015-10-09 16:11:37 10
  • Quick way to get the URL of the most recent audio file out of a podcast xml feed without any fancy xml parsing tools. Just curl, grep and head


    0
    mpc add `curl -s http://link.to/podcast/feed.xml | grep -o 'https*://[^"]*mp3' | head -1`
    tbon3r · 2015-10-11 09:17:35 9
  • this one includes special characters. note some some chars may be disallowed on windows systems. *nix will allow pretty much any character in a password except a carriage return. you do not want non printing characters in your password, so this is limited to the printable chars displayed on a keyboard , less space and return. edited to fix minor typo Show Sample Output


    0
    tr -dc '[:print:]' < /dev/urandom | fold -w10 |head -n1 |sed 's/ //g'
    wr250 · 2016-01-09 13:43:16 12
  • Returns a list, with attributes (think `ls -l`), in reverse chronological order. N is a single numeric parameter. Robust against unfriendly filenames and directory structures. Show Sample Output


    0
    nmf() { find . -type f -printf '%T@ ' -print0 -printf '\n' | sort -rn | head -"$1" | cut -f2- -d" " | tr -d "\0" | tr "\n" "\0" | xargs -0 ls -Ulh; }
    incidentnormal · 2016-03-04 14:53:14 12
  • Display the top processes sorted by memory usage. This is mostly useful because it's easy to remember and can give me a quick 'top' view of a group of servers when used over pssh. (Though I'd recommend |head -10 to minimize the output). Show Sample Output


    0
    top -b -o +%MEM |head -17
    dak1n1 · 2016-03-16 22:14:34 12
  • Grabs the first JSON file in the directory, reads its keys, prints TSV, then prints all the json files' values as TSV. Nested objects appear as json. Unhappy times if your json has literal tabs in it. Show Sample Output


    0
    jq -r 'keys | join("\t")' $(ls -f *.json | head -1) && jq -Sr 'to_entries | [ .[] | .value | tostring ] | join("\t")' *.json
    drjeats · 2016-04-08 23:30:30 12
  • This command will find any named file types in / between two dates then will list all the metadata of those files in long format and human readable form. Adding a 't' flag to the ls command sorts the files by modified time. After all that the head -5 lists the first 5 which can be changed.


    0
    ls -laht `find / -name "*.*" -type f -newermt "2016-04-05" ! -newermt "2016-04-10"`|head -5
    ubercoo · 2016-04-19 14:26:23 10
  • by determining most popular use in history using percentage . Show Sample Output


    0
    history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
    turrtle13 · 2016-04-24 17:21:35 9
  • This server can be access by a browser or other remote terminal with ncat. I have to use de test && break to allow ctrl-c to close. Show Sample Output


    0
    while [ 1 ]; do cat /dev/urandom | tr -dc ' -~' | head -c 10 | ncat -l 8080 &> /dev/null; test $? -gt 128 && break; done
    xxjcaxx · 2016-05-04 14:36:47 10

  • 0
    cat access.log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20
    prees · 2016-05-05 20:52:03 13
  • This is a alternate command I like to use instead of TOP or HTOP to see what are the processes which are taking up the most memory on a system. It shows the username, process ID, CPU usage, Memory usage, thread ID, Number of threads associated with parent process, Resident Set Size, Virtual Memory Size, start time of the process, and command arguments. Then it's sorted by memory and showing the top 10 with head. This of course can be changed to suit you needs. I have a small system which is why Firefox is taking so much resources. Show Sample Output


    0
    watch -n .8 'ps -eaLo uname,pid,pcpu,pmem,lwp,nlwp,rss,vsz,start_time,args --sort -pmem| head -10'
    ubercoo · 2016-05-11 01:05:53 11

  • 0
    find /var -type f -exec du -h {} \; | sort -rh | head -10
    jiananmail · 2016-05-31 00:21:32 10
  • Finds the login id of the user that owns the console. I use it to reset my touchpad after resume from suspend in /etc/pm/sleep.d/s99local


    0
    who | grep :0 | head -1 | cut -d " " -f 1
    mikef5410 · 2016-06-22 17:33:38 12

  • 0
    tr "\|\;" "\n" < ~/.bash_history | sed -e "s/^ //g" | cut -d " " -f 1 | sort | uniq -c | sort -rn | head -20
    turrtle13 · 2016-07-01 19:27:12 10

  • 0
    ps aux | awk '{if ($5 != 0 ) print $2,$5,$6,$11}' | sort -k2rn | head -10 | column -t
    turrtle13 · 2016-07-01 19:40:56 12
  • When bundle install sucks ...This runs isuckat_ruby.rb and when stderror matches find gem ' it will gem install what ever is missing ... Show Sample Output


    0
    gem install `ruby ./isuckat_ruby.rb 2>&1 | sed -e 's/.*find gem .//g' -e 's/ .*//g' | head -n 1`
    operat0r · 2016-08-03 19:41:27 13

  • 0
    last -x | grep shutdown | head -1
    creepyjones · 2016-08-10 21:51:48 12
  • to simulating connections Simultaneous to specific server adress to test penetrations Show Sample Output


    0
    for i in {0..60}; do (curl -Is http://46.101.214.181:10101 | head -n1 &) 2>/dev/null; sleep 1; done;
    aysadk · 2017-01-15 14:32:02 16

  • 0
    for i in {0..60}; do (curl -Is http://<domain/ip> | head -n1 &) 2>/dev/null; sleep 1; done;
    aysadk · 2017-01-24 02:47:13 13
  • To allow recursivity : find -type f -exec md5sum '{}' ';' | sort | uniq -c -w 33 | sort -gr | head -n 5 | cut -c1-7,41- Display only filenames : find -maxdepth 1 -type f -exec md5sum '{}' ';' | sort | uniq -c -w 33 | sort -gr | head -n 5 | cut -c43- Show Sample Output


    0
    find -maxdepth 1 -type f -exec md5sum '{}' ';' | sort | uniq -c -w 33 | sort -gr | head -n 5 | cut -c1-7,41-
    MaDCOw · 2017-02-09 11:36:31 18

  • 0
    head filename.txt | column -t -s $'\t'
    NLKNguyen · 2017-02-10 23:26:10 20
  • alex@alex-box:~$ sl The program 'sl' is currently not installed. You can install it by typing: sudo apt-get install sl alex@alex-box:~$ dolast Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: sl 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.


    0
    alias dolast='$( $(history 2| head -n 1| sed "s/.* //") 2>&1 | tail -n 1)'
    aheinous · 2017-02-25 01:26:49 19
  • ‹ First  < 8 9 10 11 12 >  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

find all non-html files

tcpdump whole packets to file in ascii and hex with ip adresses instead of hostname

one-line log format for svn
the output of svn log is annoying to grep, since it spreads the useful info over multiple lines. This compacts the output down to one line so eg you can grep for a comment and see the rev, date & committer straight away. Updated: MUCH shorter, easier to remember. Now it just replaces newlines with spaces, except on '---' lines.

Recover deleted Binary files
The above command assumes the lost data is on /dev/sda and you previously issued the following command to mount _another_ disk or partition (/dev/sdb1) on /recovery $sudo mount /dev/sdb1 /recovery If you don't do this, the data could be overwrited! foremost is a very powerful carving tool. By default foremost recovers all known file types. If you want to reduce the amount of files that are recovered you can specify the file type you are looking for. Read the man page to know the available file types. i.e to recover JPEG pictures append to foremost the switch -tjpg

list files recursively by size

Kill google chrome process
This one liner is to kill all google chrome tabs. This works similar to $ killall firefox command which is to kill all firefox processes.

Save your open windows to a file so they can be opened after you restart
This will save your open windows to a file (~/.windows). To start those applications: $ cat ~/.windows | while read line; do $line &; done Should work on any EWMH/NetWM compatible X Window Manager. If you use DWM or another Window Manager not using EWMH or NetWM try this: $ xwininfo -root -children | grep '^ ' | grep -v children | grep -v '' | sed -n 's/^ *\(0x[0-9a-f]*\) .*/\1/p' | uniq | while read line; do xprop -id $line _NET_WM_PID | sed -n 's/.* = \([0-9]*\)$/\1/p'; done | uniq -u | grep -v '^$' | while read line; do ps -o cmd= $line; done > ~/.windows

grep binary (hexadecimal) patterns
-P activates the Perl regular expression mode.

Paste the contents of OS X clipboard into a new text file

Printout a list of field numbers (awk index) from a CSV file with headers as first line.
Useful to identify the field number in big CSV files with large number of fields. The index is the reference to use in processing with commands like 'cut' or 'awk' involved.


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: