Commands using ls (477)

  • Delete all files that its size it's different than 0 and older than actuall day.


    0
    today=`date +%d`; ls -ltr | rm -f `nawk -v _today=$today '{ if($5 != 0 && $7 < _today) { print $9 } }'`
    alex__ · 2010-07-29 13:47:19 0
  • This version eliminates the grep before the awk, which is always good. It works for GNU core utils and ensures that the date output of ls matches the format in the pattern match, regardless of locale, etc. On BSD-based systems, you can easily eliminate both the grep and the awk: find . -maxdepth 1 -Btime -$(date +%kh%lm) -type f


    1
    ls -l --time-style=+%Y-%m-%d | awk "/$(date +'%Y-%m-%d')/ {print \$7}"
    unixmonkey11056 · 2010-07-29 05:30:29 4
  • This takes quite a while on my system. You may want to test it out with /bin first, or background it and keep working. If you want to get rid of the "No manual entry for [whatever]" and just have the [whatever], use the following sed command after this one finishes. sed -n 's/^No manual entry for \(.*\)/\1/p' nomanlist.txt Show Sample Output


    -2
    for file in $(ls /usr/bin ) ; do man -w $file 2>> nomanlist.txt >/dev/null ; done
    camocrazed · 2010-07-26 19:39:53 3
  • Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.


    -1
    rm $( ls | egrep -v 'abc|\s' )
    dbbolton · 2010-07-18 10:59:15 1
  • requires "youtube-dl" -- sure you can do this with wget and some more obscurity but why waste your time when this great tool is available? the guts consist of mplayer converting a video to a gif -- study this command and read the man page for more information mplayer video.flv -ss 00:23 -endpos 6 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound generates a 6 second gif starting at 23 seconds of play time at 5 fps and a scale of 400x300 start time (-ss)/end time (-endpos) formats: 00:00:00.000 end time should be relative to start time, not absolute. i.e. -endpos 5 == seconds after 0:42 = 0:47 end point play with fps and scale for lower gif sizes the subshell is a solution for the -b flag on youtube-dl which downloads the best quality video, sometimes, which can be various video formats $(ls ${url##*=}*| tail -n1) Show Sample Output


    12
    url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
    zed · 2010-07-18 02:11:39 1
  • This will list all symlinks that are directories under the current directory. This will help you distinguish them from regular files.


    -1
    ls -l $(find ./ -type l | perl -ne 'chomp; if (-d) { print "$_\n" }')
    rwadkins · 2010-07-16 19:31:28 0
  • You may also use the $(which foo) variant instead of backticks. I personnaly have an alias ll='ls -l'. Show Sample Output


    1
    ls -l `which foo`
    adeverteuil · 2010-07-09 01:34:02 0
  • You need to have fortune and cowsay installed. It uses a subshell to list cow files in you cow directory (this folder is default for debian based systems, others might use another folder). you can add it to your .bashrc file to have it great you with something interesting every time you start a new session. Show Sample Output


    10
    fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
    zed · 2010-07-08 02:57:52 2
  • This function does a batch edition of all OOO3 Writer files in current directory. It uses sed to search a FOO pattern into body text of each file, then replace it to foo pattern (only the first match) . I did it because I've some hundreds of OOO3 Writer files where I did need to edit one word in each ones and open up each file in OOO3 gui wasn't an option. Usage: bsro3 FOO foo


    2
    bsro3 () { P=`pwd`; S=$1; R=$2; ls *.odt > /dev/null 2>&1; if [[ $? -ne 0 ]]; then exit 1; fi; for i in *.odt; do mkdir ${P}/T; cd ${P}/T; unzip -qq "$P"/"$i"; sed -i "s/$S/$R/" ${P}/T/content.xml; zip -qq -r "$P"/"$i" *; cd ${P}; rm -rf ${P}/T; done; }
    danpos · 2010-06-30 04:43:54 2
  • Please be careful while executing the following command as you don?t want to delete the files by mistake. The best practice is to execute the same command with ls ?l to make sure you know which files will get deleted when you execute the command with rm.


    0
    find / -type f -name *.tar.gz -size +10M -exec ls -l {} \;
    0disse0 · 2010-06-29 12:39:02 2
  • This is a simple solution to running a remote program on a remote computer on the remote display through ssh. 1. Create an empty 'commander' file in the directory where you intend on running these commands. 2. Run the command 3. Hop on another computer and ssh in to the PC where you ran the command 4. cd to the directory where the 'commander' file is. 5. Test it by doing the following: echo "xeyes" > commander 6. If it worked properly, then xeyes will popup on the remote computer. Combined with my other one liner, you can place those in some start-up scripts and be able to screw with your wife/daughter/siblings, w/e by either launching programs or sending notifications(my other one liner). Also, creates a log file named comm_log in working directory that logs all commands ran.


    0
    while :;do if [ ! $(ls -l commander |cut -d ' ' -f5) -eq 0 ]; then echo "Ran command: $(less commander) @ $(date +%D) $(date +%r)" >> comm_log;"$(less commander)";> commander;fi;done
    evil · 2010-06-15 01:20:27 1
  • Run this command when you are physically at the computer you wish to send pop-up messages to. Then when you ssh in to it, you can do this: echo "guess who?" > commander guess who? will then pop up on the screen for a few moments, then disappear. You will need to create the commander file first. I mess with my wife all the time with this. i.e. echo "You have given the computer a virus. Computer will be rendered useless in 10 seconds." > commander lol


    2
    while : ; do if [ ! $(ls -l commander | cut -d ' ' -f5) -eq 0 ]; then notify-send "$(less commander)"; > commander; fi; done
    evil · 2010-06-13 18:45:02 0
  • the command will calculate the size of hidden files Show Sample Output


    1
    find directory -maxdepth 1 -type f | xargs ls -l | awk 'BEGIN { SUM=0} { SUM+=$5 } END { print SUM/2^20 }'
    emacs · 2010-06-04 01:55:01 0
  • the command will not include hidden files Show Sample Output


    -1
    ls -l directory | awk 'BEGIN { SUM=0 } { SUM+=$5 } END { print SUM/1024/1024"M" }'
    emacs · 2010-06-04 01:51:04 0

  • 1
    find / -type f -size +500000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
    kayowas · 2010-06-02 14:01:48 0
  • Finds all files below the current directory. Orders the result from smallest to largest. Good for finding the largest files in the tree.


    -2
    find . -type f -exec ls -s \{\} \; | sort -n
    Insti · 2010-06-02 11:03:31 1
  • find and normal files and list them sorting with modification time without group l: with detailed information t: sort with modification time r: reverse order h: show file's size in human-readable format, such as K(kilobytes), M(megabyes) etc. g: do not show group Show Sample Output


    -1
    find . -type f | xargs ls -ltrhg
    emacs · 2010-05-28 01:23:53 1
  • Here's a version that doesn't use find.


    -2
    ls -rl --time-style=+%s * | sed '/^$/,/^total [0-9]*$/d' | sort -nk6
    putnamhill · 2010-05-27 19:14:12 1
  • What *have* I been working on for the last 2 weeks... Show Sample Output


    0
    find . -type f -mtime -14 -exec ls -ltd \{\} \; | less
    eludom · 2010-05-27 14:54:23 2
  • List all files from the current directory and subdirectories, sorted by modification time, oldest first.


    -2
    find . -type f -exec ls -tr {} +
    goodevilgenius · 2010-05-27 14:52:28 2
  • Simple but useful; list files in the current directory in mtime order. Useful if you've been working on something and then take a day or two off. Show Sample Output


    3
    ls -lt | more
    eludom · 2010-05-27 12:44:39 2
  • rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; } Add this to your .bashrc file. Then whenever you need to remove all files/directories but one from present working directory. Run: rm-but <important-file-or-directory> Notes: 1. This doesn't affect the hidden files. 2. Argument is actually as string. And all files/directories having this string in there name are left untouched.


    1
    rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }
    sata · 2010-05-13 09:28:56 0
  • This is an updated version that some one provided me via another "find" command to find files over a certain size. Keep in mind you may have to mess around with the print values depending on your system to get the correct output you want. This was tested on FC and Cent based servers. (thanks to berta for the update) Show Sample Output


    0
    find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }'
    johnss · 2010-05-12 17:21:12 0

  • 1
    s3cmd ls s3://bucket.example.com | s3cmd del `awk '{print $4}'`
    trivoallan · 2010-05-06 16:30:48 0

  • -16
    ls | grep *.txt | while read file; do cat $file >> ./output.txt; done;
    octopus · 2010-04-16 13:19:38 1
  • ‹ First  < 10 11 12 13 14 >  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



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: