Tag Info

Hot answers tagged

44

I'll answer your questions in three parts: file types, permissions, and use cases for the various forms of chmod. File types The first character in ls -l output represents the file type; d means it's a directory. It can't be set or unset, it depends on how the file was created. You can find the complete list of file types in the ls documentation; those ...


21

du -sh is a good place to start. The options are (from man du): -s, --summarize display only a total for each argument -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) To check more than one directory and see the total, use du -sch: -c, --total produce a grand total


16

The problem most probably is that your ls has set option --color to auto which basically means that output should be coloured only if it is connected to terminal, otherwise (output connected to a pipe or a file) no colors are emitted. If you want to have colors is such cases you should set --color option to always, so try ls --color=always | less -R If ...


15

So, permissions in Linux are very important. I will try to make a short explanation. For pieces of a file mode Every Unix file has a set of permissions that determine whether you can read, write, or run the file. Running ls -l displays the permissions. Here’s an example of such a display: -rw-r--r-- 1 user somegroup 7041 Mar 26 19:34 somefile I attach a ...


11

This is by design: programs that produce colored output typically do so only when their output goes to a terminal, not when it's sent to a pipe or to a regular file. The reason is that data sent on a terminal is presumably read by a human, whereas data piped to a program or written to a file is likely to be parsed by some program, so it shouldn't contain ...


8

Just use the du command: du -sh * will give you the size of all the directories,files etc in current directory in human readable format. You can use the df command to know the free space in the disk: df -h .


7

d means it is a directory, if you have a file it is - and if it is a link you will find an l. It can't be set/unset. If you use 0777 as permissions you are giving full control (read+write+execute) to every user/group of the system. It is a lazy way to solve problems when you have users/groups that can't access directories/files. For example, if you list ...


6

Just add complete -d cd in your ~/.bashrc (or other bash configuration file).


6

du is your friend. If you just want do know the total size of a directory then jump into it and run: du -hs If you also would like to know which sub-folders spend how much disk space?! You could extend this command to: du -h --max-depth=1 | sort -hr which will give you the size of all sub-folders (level 1). The output will be sorted (largest folder on ...


5

find . or find . -ls if you want details... Using ls with a single level (directories containing files, not other directories): ls -1d -- */* for a simple list, ls -ld -- */* for details (that's the digit 1 in the first example, the letter L in lower case in the second).


4

With -path, you could try: find ~ -path '*/bin/*' -type f This won't list bin itself, so to get both: find ~ \( -path '*/bin/*' -type f \) -o \( -name bin -type d \)


4

You can get the files with full path with this command find /


4

To just get the mode: stat -c %a file (where file can also be a directory). Note: this is with the stat command from the GNU Coreutils. Otherwise the solution is system dependent.


4

The du command shows the disk usage of the file. The -h option shows results in human-readable form (e.g., 4k, 5M, 3G). du -h (file name)


3

Others have mentioned du, but I would also like to mention Ncdu -- which is an ncurses version of du and provides interactivity: You can explore the directory hierarchy directly and see the sizes of subdirectories.


3

You are almost there. find directory -type f -exec wc -lc {} + will get file name, line count, and character count. Strictly speaking, -c (a.k.a. --bytes) is documented as counting bytes, which is probably what you want.   There is also a -m (a.k.a. --chars) option for counting “characters”.  From the choice of the m option letter, I guess this counts ...


3

This works in any POSIX shell: find <directory> -type f -exec sh -c ' for f do printf "%s: %s\n" "${f%/*}" "${f##*/}" done' sh {} + This command executes on every file (file name stored in the variable f) and displays the directory (${f%/*}), a colon and the file name (${f##*/}').


3

To get all the info provided by ls -l for a single file or folder, use the -d option and specify the file: ls -ld filename


2

The simplest way is to use the --printf option as suggested by @don_crissti: stat --printf='%A %h %U %G %s %.16y %n\n' .bashrc If, for whatever reason, you can't do that you can parse the output of `stat -c '%y': $ stat -c'%A %h %U %G %s %y %n' .bashrc | awk '{$7=substr($7,1,8); $8=""}1;' -rw-r--r-- 1 terdon terdon 9737 2015-02-01 18:12:18 .bashrc Or ...


2

If your intention is to do something depending on the file permission then in some cases you can consider simple test (aka [ or [[) conditional statement: -r file exists and read permission is granted -w file exists and write permission is granted -x exists and execute permission is granted For example: [ -w file ] && echo foo >> file


2

You can use the command stat to see more metadata of the file/directory.


2

Not sure about the terminology but ls -d just lists info about the thing that follows and nothing more, ie it does NOT expand directory lists, so: ls -ld /usr/bin will just give you one line of output about /usr/bin itself. And ls -ld * will just give you info about each file or directory in the pwd but won't also expand any of the directories to ...


2

ls -d shows information about a directory or symbolic link - with this information being (in simple terms) it's respective path. The logical assumption is that the d stands for directory, since it's most basic definition in UNIX terminology I've come across is 'lists directories'. This can seem on the surface to not be that useful; say you currently reside ...


1

wc can provide both byte and line counts: find /directory/ -type f -exec wc -l -c {} + Using find is also preferable to a wildcard argument (stat ... directory/*), because the latter will fail when there are too many files in the directory for the names to fit in a single command.


1

The pattern /home/ec2-user/bitcoin/*/ expands to the list of subdirectories of the directory /home/ec2-user/bitcoin, because of the trailing slash. (Except that directories whose name starts with a . are omitted.) If /home/ec2-user/bitcoin doesn't contain any subdirectory, then the pattern doesn't match anything, so it's left unmodified. Aside: don't run ...


1

Instead ls use find -type: File is of type: b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link s socket D door (Solaris) and find -perm: -perm mode File's permission bits are exactly mode (octal or symbolic). Since an exact match is ...


1

You can do this with nested find calls: $ find ~ -type d -name bin -exec find '{}' -type f ';' Since I'm replacing an ls call, perhaps you did not want more than one level of listing in the second find call. In that case, add -maxdepth 1 after -type f above.


1

To add what @muru said in the comments; have a look at info coreutils ls `-C' `--format=vertical' List files in columns, sorted vertically. This is the default for `ls' if standard output is a terminal. It is always the default for the `dir' program. GNU `ls' uses variable width columns to display as many files as possible in the ...


1

There are two commands you can use along with ls if you intend just for the files in a particular directory. realpath readlink I can't show you realpath output as i don't have it in my system. You can make readlink to do that for you. ls | xargs -n 1 readlink -f WARNING: you may not get the abs path for the soft links as that will be converted to ...


1

As "permissions" doesn't just cover octal unix permissions on modern Linux systems, I'd like to elaborate a little: Apart from stat -c %a file @vinc17 suggested, there's stat -c %C file for the SELinux context on RHEL Systems, and getfacl file for volumes using ACLs. namei -m /path/to/file might be helpful for finding out all octal permissions leading down ...



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