Tag Info

Hot answers tagged

27

Short answer: ls -l gives the size of the file (= the amount of data it contains) ls -s --block-size 1 gives the size of the file on the file system Let's create two files: A sparse file of 128 bytes length (A sparse file is a file containing empty blocks, see Sparse File): # truncate -s 128 f_zeroes.img # hexdump -vC f_zeroes.img 00000000 00 00 00 ...


21

dir and ls are part of coreutils and dir is an alias. The GNU Core Utilities are the basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every operating system. info dir says: dir is equivalent to ls -C -b; that is, by default files are listed in columns, ...


17

There's no straightforward equivalent in ls itself, but there's the less utility, which will format the output of any command as seperate pages, scrollable by line or page: ls -C | less Where -C triggers column display. Use lah as arguments (ls -lah) to get a line by line display with all files being displayed (include hidden ones), and human readable ...


16

If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use: mv *IDENTIFIER* ~/YourPath/ * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters. This will move all the files that contain the IDENTIFIER you specified.


13

// is usually the same as /. /// must be the same as /. ls would have shown you that cd // took you to the root directory, the same as cd / does. $ cd / $ ls bin boot dev ... $ cd // $ ls (same as above) The technical way to confirm they are definitely the same directory is: $ cd / $ stat -c "%i" . 2 $ cd // $ stat -c "%i" . 2 they will print the ...


12

If you are just using ls with no arguments, it appears that you are using an alias for ls. To get the same output, I need to use ls -lF. From the ls manpage: -F, --classify append indicator (one of */=>@|) to entries -l use a long listing format The symbols mean the following: /: directories @: symbolic links |: FIFOs =: sockets *: ...


12

karthick@Ubuntu-desktop:~$ ls -n drwxr-xr-x 2 1000 1000 4096 2010-12-02 15:56 Books First Column: drwxr-xr-x It shows file permission. Second Column: 2 It shows the hard link count to that file/directory. Third nd Fourth Column: 1000 1000 It shows UID and GID of the user. Fifth column: 4096 It shows the size. Sixth column: ...


12

I believe you're talking about indicators presented by ls -F. From the manpage of ls: -F, --classify append indicator (one of */=>@|) to entries [...] --indicator-style=WORD append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F) To get an overview of the meaning of these ...


12

ls -s tells you the allocated size of the file, always a multiple of the allocation unit. ls -l tells the actual size. An easy way to test: echo 1 > sizeTest ls -l --block-size 1 sizeTest -rw-rw-r-- 1 g g 2 Mär 18 15:18 sizeTest ls -s --block-size 1 sizeTest 4096 sizeTest


9

Actually both ls and l are equal raja@badfox:~/Pictures$ l des.png Screenshot from 2012-09-22 19:37:03.png Screenshot from 2012-09-22 19:37:11.png Screenshot from 2012-09-22 19:37:12.png Untitled.png raja@badfox:~/Pictures$ ls des.png Screenshot from 2012-09-22 19:37:03.png Screenshot from 2012-09-22 19:37:11.png Screenshot from 2012-09-22 19:37:12.png ...


8

The second column is the number of hard links to the file. For a directory, the number of hard links is the number of immediate subdirectories it has plus its parent directory and itself. $ ls -n total 0 $ touch f1 $ touch f2 $ ln f1 hardlink $ ln -s f2 softlink $ mkdir d1 $ mkdir d2 $ mkdir d2/a d2/b d2/c $ ls -n total 8 drwxr-xr-x 2 1000 1000 4096 ...


8

As a one-off command you can do this: LC_COLLATE=C ls Or you can add export LC_COLLATE="C" to your .bashrc to make it permanent (may have unexpected results sorting elsewhere). More information on Ubuntu forums.


7

According to bash man page: bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern and from info node for ls The `ls' program lists information about files (of any type, including ...


7

Well this drove me mad for five minutes. Change your statement to: convert $(LC_COLLATE="C" ls -w 1000) +append sprite.png For some reason Nautilus doesn't follow the system-wide locale settings so sorts are out of sync. By faking back to the standard, sorts unify. My test harness: $ mkdir test && cd test $ touch ...


7

Do this: LS_COLORS="mh=44;37" ls -l And you may edit your ~/.profile to change LS_COLORS accordingly. Background This feature was enabled as default in 2008 has been disabled by default in 2009. Somehow the freeze for Ubuntu 10.04 was exactly in between those moments. Using the Git repository of coreutils I see that the commit to revert automatic ...


6

Just in case there isn't a built-in way to do this, you could use a simple replacement for sort: #!/usr/bin/env python import sys for i in sorted(sys.stdin): sys.stdout.write(i) Save it, for example, at /bin/pysort and make it executable (sudo cp whatever.py /bin/pysort and sudo chmod a+x /bin/pysort), and run it as ls | pysort: ...


6

You say that "ls piped to head takes an awful long time to complete". The cause of this is not ls, but the number of files in your directory. If you have 100,000 files in a single directory, any way of solving this problem would have to get information about all 100,000 files before it could even think about sorting them or printing any output. If it's ...


6

find /path/ -printf "%TY-%Tm-%Td\t%s\t%p\n" You can play with the printf formatting as much as you like. This gives you a great opportunity to get things formatted the way you need them, which is invaluable if you're using the output in another application. More: http://linux.about.com/od/commands/l/blcmdl1_find.htm For better readability, you can pipe ...


5

If 'aname' shall be the starting part of the filename, it would be, from the current directory: find -name "aname" -delete Btw.: grep "bla"* somewhere is almost always false, since grep already makes partial matches, which means, it finds bla, blafasel and xybla with simply grep bla somewhere Deleted older part of answer, because of ...


4

You can achieve this by changing the variable PROMPT_COMMAND, which is executed before PS1, e.g.: PROMPT_COMMAND='ls' This will list each time you get a new prompt. Of course you only want to execute ls if the directory has changed: PROMPT_COMMAND='[[ $my_currdir != $PWD ]] && ls; my_currdir=$PWD' This checks if the new directory isn't the ...


4

Those files are indeed executable. It's because you have (or your .bashrc file has) specified the -F option. Unfortunately the manpage is not very clear on this: -F, --classify append indicator (one of */=>@|) to entries But as far as I know * is for executables, / for directories, = for sockets, > for doors, @ for symbolic links, | for FIFOs ...


4

The answers given regarding directories will give the right number, but for the wrong reasons. The number is not a count of the subdirectories plus "." and ".." The number is actually the same as for a file: the number of hard links to the directory. For example, let us create a new directory: someuser@mymachine:~/test$ mkdir temp ...


4

Perhaps the --apparent-size option for du will do what you are after: --apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (`sparse') files, internal fragmentation, indirect blocks, and the like That should remove the dependence ...


4

Looking in the source code of coreutils, I found out that total will always be displayed when using the -l option on directories. Using the -d option to list entries instead of directory contents hides total. But if you run that without arguments (or on a directory), it'll just show the directory and not its contents. Therefore, you need wildcards. * ...


4

You can use wildcards. Example: To move all files having extension .doc mv *.doc /path/to/dest/folder/ This will move all doc file under the current directory to the specific destination. Edit To answer the comment. mv *.ext *.xml *.txt /path/to/dest/folder/


3

ls -l /mnt/my-address is showing you the files/directories inside my-address. These are only affected if you use the chown -R command to change ownership (R)ecursively. All you did was change the ownership of /mnt/my-address, not any of its contents. stat /mnt/my-address gives you information on the actual directory/mountpoint /mnt/my-address though, whose ...


3

ls will do this. The syntax for ls is: ls flags file-or-directory-names For what I'm calling file-or-directory-names, you can list files in the current directory, to have just certain files listed. For example, ls -l foo bar will list information on just foo and bar (in long form, as I've given the -l flag). ls baz*go will list all files whose names ...


3

Parsing the output of ls is unreliable. It will probably work in your case, but ls mangles unprintable characters. Here is a fully reliable way of counting the files matching a certain extension. This shell snippet creates an array containing the file names, then prints the number of elements in the array. a=(*.prj) echo ${#a[@]}


3

Sed supports up to 9 backreferences, but observing that \2\3\4 go always together, as do \5\6\7 and \8\9\10, you can use only four groups, like in the following: "s/^\([d-]\)\([r-][w-][x-]\)\([r-][w-][x-]\)\([r-][w-][x-]\)/`echo -e \"$EMG\1$EMY\2$EMR\3$EMC\4$NONE\"`/""


3

l is an alias for ls -CF, which behaves differently from plain ls. -C -C makes ls print output in column form. When stdout is a terminal (rather than being redirected to a file or non-terminal device, or piped to another command), -C is implied. So running ls -C is the same as running ls. But they are not equivalent when ls is redirected or piped. For ...



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