Tag Info

New answers tagged

1

Another alternative (piping two tr commands): ls -l partition | cut -c5-7 | tr -dc rwx | tr rwx cse


2

Alternative way without ls: getfacl -c partition | sed -n '/group::/{s/.*:://;y/rwx/cse/;s/-//g;p;}'


3

I think you want this command: ls -l partition | cut -c5-7 | tr rwx cse |sed 's/-//' You can remove the one extra command(cut -d ' ' -f 1) and replace it with your last cut command(cut -c5-7) and also add sed 's/-//' at the end to remove all -s. Now you are done. you didn't need to adding extra |. And even better: you can also change the dash(- ...


0

Your first bet if you want to keep/fix most of the content: Connect it to a real windows box, and run chkdsk /f /r upon that drive Warning: This may take several hours. Check e.g. http://technet.microsoft.com/en-us/magazine/ee872425.aspx for the usage. As the used filesystem was not specified, I'm also assuming NTFS due to the obvious autorun.inf file and ...


1

Why not just delete the annals directory? # rm -r /run/media/Harry/CA6C321E6C32062B/annals Note: It looks like it's been in a Windows machine as it has a System Volume Information directory. This means it's probably NTFS? If that's the case, then you'd be better off formatting it with a more *nix friendly filesystem. Of course, that assumes you don't ...


-2

du -hs /path/* Example: [root@site02 ~]# du -hs /tmp/* 4.0K /tmp/hsperfdata_root 4.0K /tmp/keyring-IbsPYd 4.0K /tmp/mc-root 0 /tmp/mongodb-27017.sock 8.0K /tmp/orbit-root 508K /tmp/pear 4.0K /tmp/pulse-p9Spgn0sr62Y 4.0K /tmp/rabbitvcs-112Mzm 4.0K /tmp/rabbitvcs-8CShnI 4.0K /tmp/rabbitvcs-AQyi1m 4.0K /tmp/rabbitvcs-DxGqTB ...


1

If you are using bash try to put this in your bashrc/bash_profile: alias cd='cd $1 && ls -lrth' UPDATE: This is not correct, i just double checked it, it is just listing the dir you did want to cd in but it stays in your actual dir where you launched the command. UPDATE 2: You have to create a bash function instead of an alias it is much safer ...


0

It is not the bug in ls. It is the way symlinks work. in case of ls -a ls just shows file list in current directory in case of ls -a ../cur_dir ls resolves current directory in absolute path goes one level up outputs file list in this location


0

The equivalent in BSD or OSX is $ du -ah simpl | sort -dr | head -6


0

You should select which time you need %y modification %w creation %z change or any combination: stat * --printf="%n\t%y %z\n" | grep -vF $(date -d "last Saturday" +%F) | cut -f1 Also choice what infomation you need and compose --printf= line. Or you can use just find command find -maxdepth 1 -type f -daystart \ ! -mtime $[$(date +%d)-$(date -d ...


2

If you are looking for directories that are using up space, and are not on a different partition, then you want du -hx --max-depth=1 /. The -x tells it not to descend into directories that are on other filesystems ( partitions ). The --max-depth=1 asks to only print a line ( listing the total space for that directory and all subdirectories ) for each ...


1

Simpler: find . -maxdepth 1 -printf '%Ta\t%p\n' | grep -v -i '^sat' ref: This answer.


1

A way to do this : $ LANG=C find . -maxdepth 1 -printf '%p %AA\n' | awk '$NF=="Saturday"{next}{$NF=""}1' I assume we don't print files for all Saturdays. This is or not what you expect.


1

If I am reading this question correctly, there is a program called tree. This would list all directories in a tree like structure. With it installed, you can do something like: tree -x Where -x Stay on the current file-system only. Ala find -xdev. UPDATE: I have tried tree -P /dev/xvda and it seemed to have shown directories under that filesystem. The -P ...


0

But, how will I know the list of directories under /sda2? There are no directories under /dev/sda2, /dev/sda2 is a partition on the disk (sda is the disk and 2 is the partitions number). But, is there any command or way through which I can also list down their filesystem too? Since you only have one filesystem mounted then they are all on the / ...


3

That is because you need option -l for that. -a is to also show hidden files. Extract from the manual man ls: -a, --all do not ignore entries starting with . … -l use a long listing format It is the long format that you are looking for.


3

Yes, your shell tries to be smart on changing to a symlink directory: $ mkdir a $ ln -s a b $ cd b $ pwd /home/michas/b $ pwd -P /home/michas/a After changing to symlink b your shell pretends you are really in "directory" b but instead the symlink sent you to directory a. See help pwd: -P print the physical directory, without any symbolic links ...


1

You can get the real path, with links resolved using realpath and compare the output realpath ../../../../.. cd ../../../../.. realpath . On my system: ~/shared $ realpath .. /home/avdndata/lnk ~/shared $ cd .. ~ $ realpath . /home/anthon


7

Reset your path right now with: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin It doesn't get your full PATH restored but basic utilities will be available again. Here's what probably happened: You had a PATH variable (referred to as $PATH when reading from it) Something like: $ echo $PATH ...


7

The changes you've made to PATH are likely temporary. Close the shell you're in with exit and reopen it. In the event that you have edited a file that sets the PATH for newly opened shells, specify the full path to commands to fix whatever you've changed (eg. /usr/bin/vim).


0

If you can use ls, then I assume you can use builtin bash functionality too. Using pure bash to count all entries in the current directory: $ num_entries () ( # Define a function to: > shopt -s nullglob # expand * to empty string if no files > shopt -s dotglob # include .files in * expansion > a=( * ) # create array ...


3

Since, you want to decipher from the output that you have got, we will try and simplify things. ls -ld drwxr-xr-x 4 root root 4096 Nov 11 14:29 . Now, ls -ld on a directory gives me the output as above. Now, the number 4 is something that you need to concentrate on. The 4 corresponds to: the entry for that directory in its parent directory; the ...


0

You may combine a couple of approaches Number of files in a directory ls -l | grep "^-" | wc -l Walk through subdirectories find ./subdirectory -type d put together in one command find ./subdirectory -type d | xargs -I{} sh -c "ls -l {} | grep -c '^-'" Will recursively result a count of files restisting in the directories. Of course there a ...


0

In a simple case this works: ls -A1 | wc -l


-1

Change the command to execute to echo: find / -type d -mount -exec echo {} \;


1

POSIXly: find / -xdev -type d -exec sh -c 'for d; do ls -lsd "$d"/*; done' sh {} + -xdev has the same affect as -mount but is portable. A note that this will fail on empty directory.


0

That is the usual behaviour of ls when a directory is given as argument. So you have to avoid ls handling directories specially. You must pass file paths to ls, i.e. -type f instead of -type d. If you want to pass directories, too, (no -type f) then you need the option -d for ls.


1

The command ls is dealing with file names, which are recorded in the directory data structures. So it does not really care about the file itself, including the "type" of a file. A command that is more suited to working on actual files, not only it's names, is find. It has an option that directly answers your question on how to filter the list on file type. ...


5

If you want to display all the output but have files of similar type listed together, you can sort the output on the first character of each line: ls -l | sort -k1,1


1

ls -l | awk '/^d/{print $NF} awk will catch all that start with d. as d is for directory and you need to print last field to list directory name


1

ls -l | sort This will sort the result according to the alphabetical order of each result. If the first character is the criteria you want, that's it. If you need the file names only you can try: ls -l | sort | cut -f 2 -d ' ' Or something similar (that command sorts and then splits each line using the space delimiter,then returns the second group.


2

If you are most concerned about ordering the folders from the other file types, you could go with ls --group-directories-first else, I think you have to pipe the output from ls -l through sort or through grep as answered by Anthon


3

You can filter out everything but directories using grep this way: ls -l | grep '^d' the ^ indicates that the pattern is at the beginning of the line. Replace d with -, l, etc., as applicable. You can of course use other commands to directly search for specific types (e.g. find . -maxdepth 1 -type d) or use ls -l | sort to group similar types together ...


2

You can also sort by octal value. for i in *; do stat --format="%a %n" "$i"; done | sort -n


4

ls does not directly support sorting by permissions, but you can combine it with the sort command: ls -l | sort You can use the -k option to sort to start matching from a specific character, the format is -k FIELD.CHAR, the permissions are the first field in the ls output. So e.g. -k 1.2 will start from the second character of the permission string, which ...


0

I'm not sure what version of OSX & the various tools you are using but I have the following setup on my OSX system and ls -G shows the same column alignments as the vanilla ls. Examples     My setup consist of the following environment variables. $ env|grep -Ei "cli|ls|col" TERM=xterm-256color CLICOLOR=1 LSCOLORS=GxFxCxDxBxegedabagaced ...


1

The multi-line answers above didn't suit my desire for a one-line solution and not modifying the environment. Here is a generic one-liner that may work for you: echo $(ls FOO* 2>/dev/null | wc -w) the /dev/null is because ls throws an error if there's no file. This just ignores ls and counts the number of files found based on the number of "words" ...


0

I used xargs with find : find . -type f | xargs -i sh -c 'echo -n `date -r {}`; \ echo -n " "; echo -n `wc -l {}`; echo ' Output: Thu Oct 30 19:16:38 IST 2014 0 ./b Thu Oct 30 19:16:38 IST 2014 0 ./a Thu Oct 30 19:16:38 IST 2014 0 ./c Thu Oct 30 19:16:56 IST 2014 10 ./testfile Little formatting with printf instead of echo as done ...


2

The find-based solutions look the most elegant, but just for fun here are a couple of other ways to attack this. This one uses sed & head to clean up the output of wc, then uses join to combine that to the output of stat, using the file name as the join field. pat="A*";join -1 2 -2 1 -t ' ' <(wc -l $pat|head -n-1|sed 's/^[ ]*//') <(stat -c '%n ...


0

I used awk as shown below: wc -l * | head --lines=-1 | while read num file do echo -n $num" " ls -l $file | awk '{ for (i=6; i <= NF; i++) printf $i " " }' echo done head is used to remove the last line (total line of wc output). num contains the number of line of file. awk is used to print the time output from ls -l output.


6

Here is something with find + wc + date. find . -maxdepth 1 -exec sh -c '[ -f "$0" ] && \ printf "%6s\t\t%s\t%s\n" "$(wc -l<"$0")" "$(date -r "$0")" "$0"' {} \; Instead of date -r one can also use for example stat -c%y. The output looks like this: 394 Thu Oct 16 22:38:14 UTC 2014 ./.zshrc 7 Thu Oct 30 11:19:01 UTC 2014 ...


-2

What about : ls -lrth yourfile|awk '{print $6 $7 " " $8 system("wc -l " $9) }' > /tmp/temp.txt tr '\n' ' ' < /tmp/temp.txt



Top 50 recent answers are included