
Terminal - Commands using ls - 408 results
ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
This is sample output - yours may be different.
svn ls -R | egrep -v -e "\/$" | tr '\n' '\0' | xargs -0 svn blame | awk '{print $2}' | sort | uniq -c | sort -nr
This is sample output - yours may be different.
make usable on OSX with filenames containing spaces. note: will still break if filenames contain newlines... possible, but who does that?!
ssh -t myserver.org 'sudo ls /etc'
This is sample output - yours may be different.
This command will ask for remote sudo password before executing a remote command.
This is sample output - yours may be different.
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
This is sample output - yours may be different.
|-Albumn
|---config
|---src
|-----Albumn
|-------Controller
|-------Form
|-------Model
|---view
|-----album
|-------album
A way to display directory structure
This is sample output - yours may be different.
This will show you the permissions on the directory you are currently in
ps aux | grep [process] | awk '{print $2}' | xargs -I % ls /proc/%/fd | wc -l
This is sample output - yours may be different.
while true; do ls -all myfile; spleep 1; clear; done
This is sample output - yours may be different.
-rw-r--r-- 1 user sudo 13456 mar 26 10:07 myfile
Sometime you need to monitor file or direcory change in dimension or other attributes. This command output file (called myfile in the example) attributes in the top of the screen, updating each 1 second.
You should change update time, command ( e.g., ls -all ) or target ( myfile, mydir, etc...).
This is sample output - yours may be different.
zsh globbing and glob qualifier:
'**/*' = recursive
om = ouput by modification (last access)
[1,20] = twenty files.
The '-t' switch is provided to ls so that the files are ordered with the most recent at the top. For a more 'find' like output the following can be used.
print -rl **/*(om[1,20])
ls -Sh **/*(.Lm+100) | tail -5
This is sample output - yours may be different.
zsh: list of files sorted by size, greater than 100mb, head the top 5. '**/*' is recursive, and the glob qualifiers provide '.' = regular file, 'L' size, which is followed by 'm' = 'megabyte', and finally '+100' = a value of 100
find -type f | xargs ls -1tr
This is sample output - yours may be different.
find . -type f -exec ls -s {} \; | sort -n -r | head -5
This is sample output - yours may be different.
This is sample output - yours may be different.
ls -qahlSr # list all files in size order - largest last
This is sample output - yours may be different.
$ ls -qahlSr # list all files in size order - largest last
[text deleted]
-rw-r--r-- 1 mpb cdrom 469M Mar 4 2012 VMware-workstation-full-8.0.2-591240.exe
-rw-r--r-- 1 mpb cdrom 475M Nov 20 2011 VMware-workstation-full-8.0.1-528992.exe
-rw-r--r-- 1 mpb cdrom 491M Dec 12 2011 OpenVAS_4_VM.x86_64-0.0.27.iso
-rw-r--r-- 1 mpb cdrom 695M Jul 16 2012 Mageia-2-LiveCD-GNOME-Europe1-Americas-x86_64-CD.iso
-rw-r--r-- 1 mpb cdrom 695M Jul 18 2012 Mageia-2-LiveCD-GNOME-Europe1-Americas-x86_64-CD (1).iso
I find it useful, when cleaning up deleting unwanted files to make more space, to list in size order so I can delete the largest first.
Note that using "q" shows files with non-printing characters in name.
In this sample output (above), I found two copies of the same iso file both of which are immediate "delete candidates" for me.
This is sample output - yours may be different.
drwxr-xr-x 3 root root 4096 abr 25 2012 acpi
drwxr-xr-x 2 root root 20480 feb 28 13:55 alternatives
drwxr-xr-x 6 root root 4096 abr 25 2012 apm
drwxr-xr-x 3 root root 4096 may 3 2012 apparmor
drwxr-xr-x 6 root root 4096 feb 23 13:06 apparmor.d
drwxr-xr-x 5 root root 4096 feb 13 12:42 apport
drwxr-xr-x 6 root root 4096 feb 28 13:55 apt
drwxr-xr-x 2 root root 4096 oct 25 20:30 at-spi2
drwxr-xr-x 3 root root 4096 abr 25 2012 avahi
drwxr-xr-x 3 root root 4096 feb 16 14:13 bash_completion.d
drwxr-xr-x 2 root root 4096 abr 25 2012 bluetooth
drwxr-xr-x 2 root root 4096 oct 25 20:29 bonobo-activation
ls -qaltr # list directory in chronological order, most recent files at end of list
This is sample output - yours may be different.
[mpb@localhost ~]$ ls -qaltr /tmp
total 12
drwxr-xr-x 19 root root 4096 Jan 12 09:12 ../
drwxrwxrwt 2 root root 40 Feb 25 13:29 .XIM-unix/
drwxrwxrwt 2 root root 40 Feb 25 13:29 .Test-unix/
drwxrwxrwt 2 root root 40 Feb 25 13:29 .font-unix/
-rw-r--r-- 1 root root 157 Feb 25 13:29 ddebug.log
drwxrwxrwt 2 root root 40 Feb 25 13:29 systemd-private-BsJC1l/
-r--r--r-- 1 root root 11 Feb 25 13:29 .X0-lock
drwxrwxrwt 2 root root 60 Feb 25 13:29 .X11-unix/
drwx------ 2 root root 40 Feb 25 13:29 pulse-PKdhtXMmr18n/
drwx------ 2 root root 60 Feb 25 13:29 gpg-JYxEia/
drwx------ 2 root root 60 Feb 25 13:29 gpg-9EimL6/
drwx------ 2 mpb mpb 60 Feb 25 13:29 gpg-0tXbPf/
-rw------- 1 mpb mpb 0 Feb 25 13:29 xerr-mpb-:0
drwxrwxrwt 2 root root 40 Feb 25 13:29 systemd-private-Agvb8o/
drwx------ 2 mpb mpb 60 Feb 25 13:29 .esd-10001/
drwxrwxrwt 2 root root 60 Feb 25 13:29 .ICE-unix/
drwxrwxrwt 2 root root 40 Feb 25 13:29 systemd-private-q2rBI6/
drwxrwxrwt 2 root root 40 Feb 25 13:30 systemd-private-KBB9hs/
srwxr-xr-x 1 root root 0 Feb 25 13:30 wpa_ctrl_3263-0=
drwx------ 2 root root 60 Feb 25 13:31 gpg-dVH2Yz/
drwx------ 2 mpb mpb 80 Feb 25 13:42 CRX_75DAF8CB7768/
drwx------ 2 mpb mpb 80 Feb 25 14:00 .com.google.Chrome.nczGuc/
-rw-rw-r-- 1 mpb mpb 0 Feb 25 14:01 .google-talk-plugin-mpb.lock
drwxrwxrwt 2 root root 60 Feb 25 14:09 systemd-private-Iu9cH6/
drwxrwxrwt 20 root root 500 Feb 25 14:12 ./
I find it very handy to be able to quickly see the most recently modified/created files in a directory.
Note that the "q" option will reveal any files with non-printable characters in their filename.
This is sample output - yours may be different.
dr-xr-xr-x 7 root root 4.0K Jan 29 2009 370/
drwxr-xr-x 3 root root 4.0K Jul 17 2010 viva/
drwxr-xr-x 2 root root 4.0K Nov 1 2011 ktop/
drwxr-xr-x 2 oracle oinstall 4.0K Apr 17 2012 1704/
list only directories in reverse order
ls -lT -rt | grep "^-" | awk 'BEGIN {START=2002} (START <= $9){ print $10 ;START=$9 }' | tail -1
This is sample output - yours may be different.
On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.
This is sample output - yours may be different.
ls -a | du --max-depth=1 -h 2>/dev/null |sort -h
This is sample output - yours may be different.
touch file{1..10}.txt ; ls *txt| sed -e "p;s/\.txt$/\.csv/"|xargs -n2 mv
This is sample output - yours may be different.
for x in `ps -u 500 u | grep java | awk '{ print $2 }'`;do ls /proc/$x/fd|wc -l;done
This is sample output - yours may be different.
cd $(ls -1 | sed -n '<N>p')
This is sample output - yours may be different.
cd $(ls -1 | sed -n <N>p)
This is sample output - yours may be different.
for i in `pfiles pid|grep S_IFREG|awk '{print $5}'|awk -F":" '{print $2}'`; do find / -inum $i |xargs ls -lah; done
This is sample output - yours may be different.
user@machine# for i in `pfiles 25925|grep S_IFREG|awk '{print $5}'|awk -F":" '{print $2}'`; do find /path/tmp -inum $i |xargs ls -lah; done
-rw-r--r-- 1 user group 910 Jan 26 2012 /path/tmp/file1.prm
-rw-rw-rw- 1 user group 6.3K Jan 20 06:30 /path/tmp/file2.rpt
-rw-r--r-- 1 user group 86K Jan 23 23:34 /path/tmp/file3.log
-rwxrw-r-- 1 user group 65 Dec 26 07:27 /path/tmp/file4.pcr
Executing pfiles will return a list of all descriptors utilized by the process
We are interested in the S_IFREG entries since they are pointing usually to files
In the line, there is the inode number of the file which we use in order to find the filename.
The only bad thing is that in order not to search from / you have to suspect where could possibly be the file.
Improvements more than welcome.
lsof was not available in my case