Tag Info

Hot answers tagged

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).


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 ...


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


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 ...


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(- ...


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 ...


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 ...


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

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 ...


2

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


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 ...


2

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


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


1

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


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 ...


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 ...


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 ...


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


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.


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. ...


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.


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" ...



Only top voted, non community-wiki answers of a minimum length are eligible