New answers tagged

0

In many *nix distributions this is turned on by default in the users .bashrc. Edit ~/.bashrc and remove the line that looks like: alias ls='ls --color=auto' If you wish to disable this feature for all new accounts generated on this machine in the future, remove the same line from: /etc/skel/.bashrc


3

You can use moreutils sponge: ls | sponge list Or with zsh: cp =(ls) list With GNU ls: ls -I list > list (though if there had been a file called list before, that means it won't be listed). Since ls output is sorted anyway, you can also use (assuming your filenames don't contain newline characters): ls | sort -o list Or to avoid the double ...


2

Partial/most credit goes to @StephenHarris... echo "`ls`" > list equivalent to echo "$(ls)" > list


9

As you've noticed, the file is created before ls is run. This is due to how the shell handles its order of operations. In order to do ls > file the shell needs to create file and then set stdout to point to that and the finally run the ls program. So you have some options. Create the file in another directory (eg /tmp) and then mv it to the final ...


8

The output file is created by the shell before ls begins. You can get around this by using tee: ls | tee list To thoroughly defeat any race condition, there is always ls | grep -vx 'list' > list Or if you like that tee displays the results as well: ls | grep -vx 'list' | tee list However, as pointed out in comments, things like this often break ...


3

You can make the filename temporarily hidden: ls >.list && mv .list list


4

This is not caching. You have to understand that in UNIX-like operating systems, there is a distinction between a name of a file, the file itself, and its contents. For example, a file might be found at /home/adam/myfile, but this maps to an 'inode' in the underlying filesystem. A hardlink is a different name for the same inode. The inode maps to some data ...


14

This can happen if the current directory is renamed or moved while you're in it. For example: $ mkdir /tmp/X $ cd /tmp/X $ mkdir Y Z $ cd Y $ touch a b c d e f $ mv ../Y ../A $ mv ../Z ../Y $ echo $PWD /tmp/X/Y $ ls a b c d e f $ ls $PWD $ You can spot the difference in looking at the inode number of the directory: $ ls -ldi . $PWD 26871815 drwxr-...


1

John1024 has added a good solution to your apparent problem, but based on the comments, you'd like to understand extglob better. I suspect that one of the core misunderstandings may have been that extglobs would work in a recursive manner -- that saying ./public_html/!(*uploads*) would exclude something named ./public_html/wp-content/uploads/. The globs (...


0

Solution: List files in target dir Replace to wildcard match with sed Pipe to rsync --exclude-from find target_dir | sed -r 's/\.\/(.+?)-.*/\1*/' | rsync --verbose --ignore-existing --exclude-from - src_dir/* target_dir


0

drwx--xrwx this means that d is directory the rwxis that this the owner of this direcotry has read/write/execute permitions the next --x is that the users that belong to the group that owns this directory have execute permitions and the last rwx everyone else (not the owner of directory or any member of the owner group of directory can read/write/execute ...


0

SELinux provides a user (unconfined_u), a role (object_r), a type (user_home_t), and a level (s0). This information is used to make access control decisions. On DAC systems, access is controlled based on Linux user and group IDs. SELinux policy rules are checked after DAC rules. SELinux policy rules are not used if DAC rules deny access first. This link ...


3

It's possible for a command to detect when its output is going to a TTY or not. Thus in this particular case, when ls detects that its output is not going to a TTY, it behaves as if -1 were passed as an argument. You can see this, and that grep is not doing anything special by using cat: ls | cat


2

To see how ls behaves when its output is being redirected, you can try running ls | cat or ls -1 which is how ls behaves when its output doesn't go to a TTY.


5

First, the extglob controls what ls sees on its command line. It does not control what ls does with what it sees on the command line. This is important because the -R option to ls tells ls to explore recursively any directories it sees on the command line. So, even if the *uploads* directories are not given explicitly on the command line, ls will find them ...


3

From the mv man page -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY mv's default behavior is to move everything into the last argument so when xargs executes the command it does it like mv /destinationFolder pipedArgs without the -t it would try to move everything into the last arg piped to xargs. With the -t ...


1

GNU ls gives you a choice between coloring files by their type or (if a given type is not colored) by a pattern. That is done by the dircolors program which has a built-in database of types, patterns and colors. ls does not care about the directory path itself. The aspect of "where they refer to" is not easily done with that program. Symbolic links ...


0

All hard-linked files can be shown in bold-red by modifying the command LS_COLORS="*.tgz=01;31:mh=04" ls --color=auto foo.tgz to LS_COLORS="*.tgz=01;31:mh=04;01;31" ls --color=auto foo.tgz The mh= part of the LS_COLORS variable refers to hard-linked files. There is a table in the ls source code which does not appear in the documentation: enum ...


3

It looks like that's actually the username. Try checking the passwd file, and you might find that somebody tried to comment out a line: grep owner /etc/passwd If you find that there is a line starting with #, then if there is another line which doesn't have it, you may want to remove the line with the #. Otherwise, you may just want to remove the #. That ...


1

from man ls -h, --human-readable with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G) Meaning that it will display file sizes using K, M, G postfixes: 1K = 1024, 1M = 1024K, 1G = 1024M (all in bytes). see http://www.athropolis.com/popup/c-comp2.htm This is very similar to how the metric (SI) system works ( 1000μ = ...


0

List files by size ascending would be: ls -lSr The options are: l: long, shows detailed user,group,other attributes, date, etc. S: orders listing by size (descending by default) r: reverses order of listing


0

Agreeing with @nsg that you cannot do this, it seems that the documentation is lacking. So you can read the source-code for ls, in print_color_indicator, in particular the place where it checks file-suffix, commenting /* Check the file's suffix only if still classified as C_FILE. */ So, no: you cannot fool it by making a directory-name ending with ".jpg"...


0

As I understands it, you can only specify files that ends with a specific pattern, for example *.jpg=01;31 to make jpg-files red. Then of course you can always trick it with something like this *IMG_20150808_202948.jpg=01;31 :)



Top 50 recent answers are included