The ls command lists the contents of a directory.

learn more… | top users | synonyms

3
votes
3answers
352 views

List the first 4 lines of all the files in a given directory

What command could I create that will list the first 4 lines of all the files in a given directory?
0
votes
0answers
17 views

How are the sizes of Linux directories determined? [duplicate]

The results of ls -lh provides, among other things, a listing of subdirectories and their sizes. As the directories' sizes are not determined by the sum of the files within them, how are they ...
1
vote
2answers
106 views

`du -b` shows different size than `ls`

I have a directory with a few hundred files (real files, no symlinks, no subdirectories). When I use ls -la and sum up the sizes in Excel I get 287190 bytes(?). When I use du -b or du --apparent-...
0
votes
1answer
80 views

how to get latest file in each dir

Is there a Unix command to get the latest file in logsarchive of each dir of /app/instance? In the example below, I have 5 folders in /app/instance: as_a, as_b, as_c, aunz, naeu and I need to get the ...
0
votes
1answer
71 views

bash: How to determine the largest number (newest version) from: ls *.tar.gz | cut -c 2-4

Hi I'm trying to get the largest number (newest version) of a file, I got a bunch of tar.gz files in a directory, versions of some software in the format v${version_number}_software.tar.gz, where ${...
0
votes
1answer
39 views

ls without --time-style support

I need the achieve the same output in FMTIME as achieved by the following command: FMTIME=`ls -l --time-style=+%s $FILE | cut -f6 -d' '` but my linux does not support --time-style. I am running :: ...
1
vote
3answers
80 views

How use an if statement to change the output message

When i run this command it still outputs the same message when nothing is in the waste bin directory, how could I get the command to output a different message when there are no files in the bin? ...
1
vote
2answers
516 views

File Permissions Sticky&User Execution

After the website of a client has been hacked, I found some files with the following permissions set What exactly S and T stands for? Also, which one is the command to set them with those ...
2
votes
1answer
537 views

passing variables from 'ls' to 'tar' via 'xargs'

I am trying to do something like ls -t | head -n 3 | xargs -I {} tar -cf t.tar {} to archive the 3 last modified files but it ends up running the tar command separately for each of the files and at ...
2
votes
1answer
119 views

ls after cd in tcsh?

I cannot seem to find an answer to this question. In my .bash_profile I have this line: cd() { builtin cd "$@"; ll; } which executes ll every time I change directories. I would like this ...
1
vote
1answer
623 views

ls: No such file or directory error

I am writing a very basic shell for my school. Even thought commands like "pwd" or "date" works when i try "ls" it shows me that "ls: No such file or directory error" The code of my shell is bellow:...
0
votes
1answer
88 views

How do I do a long listing of files and only show those that are a certain size?

I need to show a long listing of files in a directory but only those that are a certain size in bytes. Can someone tell me how to do this?
2
votes
5answers
255 views

How can I list the names of directories that contain file names matching a regex?

Given a directory X that contains several subdirectories and files, I would like to list the names of the immediate child directories of X that (directly or indirectly) contain file names matching the ...
3
votes
5answers
610 views

Search files for a string and if found check if a file with paired name exists in the same directory

I have many different files with the same ending .ft1 that may or may not contain one specific word special. For the files that contain this word, I want to check whether another file with a different ...
0
votes
1answer
37 views

Using `tree`, how do I output files before subdirectories?

I tried to combine --dirsfirst and -r, but directories still show up on top, only in reverse alphabetical order. It seems like -r is applied first, which is also indicated by the man pages. Any other ...
0
votes
0answers
28 views

How can binary names in command prompt be colored

I recently saw in a presentation that the typed in commands that matched something in /bin /sbin /... were colored green. It looked nice and felt more structured. How can this be achieved with ...
1
vote
0answers
34 views

`ls\` logs out of terminal session?

Like many, I have an alias ll=ls -l[.]+ set. A moment ago, I typed ll and then accidentally hit \ on the way to return. I hit return again to finish the command (on the continued line prompt), ...
0
votes
0answers
11 views

List extensions of files and their amount [duplicate]

I want to list file extensions and the number of files for this extensions at once. I tried this: ls -R | grep -Eo "\..+" | sort -u|wc -l but it only count the number of file extensions, without wc -l ...
1
vote
1answer
90 views

sshfs: permission denied when trying to access specific folder

I can access to my specific folder like this: ssh -YX xxx@xxxxxx.xxx.xxxx.xx cd ../the/folder/I/want or with an absolute path ssh -YX xxx@xxxxxx.xxx.xxxx.xx cd /the/absolute/path/to/the/...
0
votes
3answers
126 views

How to list all files *.html bigger than {size} excluding some {*parts*}

I need a command to list files. But I have three problems: I want files ending with .HTML and .HTM If any file has parts like: google docs or form in the name, I want to exclude it. I want just ...
0
votes
2answers
406 views

Fix LS Colors for directories with 777 permission? [duplicate]

When I run ls on a folder with directories that have a 777 permission, the ls colors are purple text with a green background, which is unreadable: What can I do to make this more pleasant to look ...
1
vote
1answer
72 views

How to make ls warning me about parent directory is symlink

I just found a scenario which i (or someone new to linux) might accidentally rm file because user thought it's duplicated file. Let's say i have this two binary files: [xiaobai@xiaobai note]$ ls -...
5
votes
2answers
656 views

How do I get the total size of everything in a directory in one line? [duplicate]

I know I can use du -h to output the total size of a directory. But when it contains other subdirectories, the output would be something like: du -h /root/test . . . . 24K /root/test/1 64K /root/...
3
votes
1answer
155 views

OS X: Can `ls` show broken symlinks?

When in Linux, I enjoy having \ls -l --color=auto show broken symlinks with red text for the name of the symlink and blinking text for the missing linkee. But in OS X, \ls -lG (the closest thing I ...
0
votes
2answers
114 views

What does “ls --dired - l” or “ls -D -l” actually print?

ls --dired -l prints all dir and files along with some number followed by //DIRED// ***66 69 122 131 ....*** //DIRED-OPTIONS// --quoting-style=literal What do these numbers in bold mean? --dired ...
3
votes
1answer
53 views

How to list files named like XXXmmyy.dat in natural chronological order?

I use a Mac OS X (V10.9.5) and work in the X11 window, and I often need to deal with thousands of files named like XXXmmyy.dat, where XXX is a 3-letter acronym of a place, mm is the 2-digit month, and ...
1
vote
1answer
36 views

Only color files according to file types? [duplicate]

When using ls to list files in a directory, the files are colored according to their access permissions. Is it possible to color the files only according to their file types (e.g. a regular file, a ...
1
vote
1answer
277 views

ls -l without file permissions

How can I use ls while using -l (long listing) without showing the file permissions? Right now I have the following alias for ls: alias ls='ls -lhaG --color=auto' I have found a solution close to ...
1
vote
2answers
265 views

Changing colors used by `ls` does not work in Emacs “Shell” mode

I followed http://unix.stackexchange.com/a/94508/674 to change the colors used by ls. This works in bash. When I open a buffer of "Shell" mode in Emacs (M-x shell), the change doesn't work. I wonder ...
10
votes
4answers
733 views

List files that match a pattern but ignore files that match another pattern?

Let's say I have a directory with files a1, a2, a3, b1, b2, b3. I only want to match files that start with a but don't contain 3. I tried ls -I "*3" *a* but it returns a1 a2 a3, even though I don't ...
8
votes
5answers
4k views

Why does “ls -all” show year or time?

If you issue ls -all command some files or directories have the year and some have the time? Why do some show the year while others show the time? Is the time representative of the time the file was ...
1
vote
2answers
84 views

Finding a file which has “info” in its title

By using the ls command I can list the names of all the files in the directory I am working with. However, how do I list all of the files in the directory which have contained in their title info? So ...
3
votes
3answers
185 views

Why size reporting for directories is different than other files?

I was wondering why an empty directory occupied 4096 bytes of space and I have seen this question. It is stated that space is allocated in blocks and hence, the size of a new directory is 4096 bytes. ...
0
votes
0answers
159 views

Cannot see files present on server when connecting via Filezilla / SFTP

I am not able to see the files present on the server using Filezilla ftp client. I am using SFTP connection. I am able to connect to the server. I can see only the directories but not the files. ...
3
votes
1answer
25 views

How can you group symlinks with directories in `ls` output but tell the difference?

In ls output, I'd like to group symlinks that point to directories along with the rest of the directories, but still have a way of telling that it's a symlink either with color or an appended symbol. ...
0
votes
2answers
271 views

Script that list file names by first letter bash type [closed]

I need a script that takes input from the user which specifies the first letter of the file names to be displayed, so that only file names starting with the letter specified are listed. I only need to ...
-3
votes
2answers
418 views

List all files that end in “ball” using ls command [closed]

I am trying to use ls command to find specific files that Have 4 letters in front of the word "ball" Must have the ending word "ball" I have been trying to use ls *ball but this shows words with 4 ...
1
vote
2answers
101 views

How to extend the ls command by a custom column

I wonder if it is possible to modify the ls -l command by a custom column. For example, I would like this column to contain for each file, say, the first line of $(CustomCommand FILE).
4
votes
5answers
644 views

How to list the n'th youngest file (without parsing ls!)

So I know parsing ls is bad!. Today I found this nugget: FILENAME=`ls -t $READ_FOLDER | head -1` So I believe originally this was designed to grab the newest filename, I actually now want to adapt ...
1
vote
3answers
74 views

How to list atime for files?

According to this post can stat be used to give the atime on Linux, but FreeBSD 10.1 doesn't have the GNU stat. How do I list the atime for files?
5
votes
1answer
142 views

Non-standard sorting of the ls output

I usually include a date in the filename so that files and directories are listed in chronological order when I use the ls command, e.g. 2015-08-29_letter_to_santa.txt. A drawback is that tab-...
1
vote
1answer
120 views

How to know if output is being redirected to a file? [duplicate]

I am working on displaying output like ls command (just ls, no options). And I have a working program using the system calls. But I experienced a strange behavior while testing as shown below. $ ls ...
1
vote
5answers
88 views

Making a *nicely* formatted list of number of files in directories - awk & sed probably

I have lots and lots of files in a series of directories, and would like a nicely formatted list of how many files are in each directory. The directories are ordered thus: Parent directories named A,...
1
vote
1answer
35 views

LS_COLORS mixing matching criteria, e.g. file extension and hardlink

I'm wondering if there is a way to keep the characteristic color of the extension type in ls --color=auto as well as underlining the file if it is a hard link. For instance, if I do LS_COLORS="*....
3
votes
1answer
125 views

“Display all <num> possibilities? (y or n)” for ls command

When I attempt to tab complete a filename in the bash prompt, and the output would be many (>100) filenames, the shell asks Display all <num> possibilities? (y or n) Can I replicate this ...
2
votes
1answer
568 views

Why root bash output is colored but `sudo ls` output is not?

In bash (I am using Ubuntu 12.04) I get colored outputs either as root (after sudo su) or as a normal user. I checked (after reading this post) the files .bashrc for normal user and superuser and ...
0
votes
1answer
642 views

get list of files which are unique

I have a directory in which files are created as abc.sh.ID.datetimestamp.id.log In the filename abc.sh, the ID is always the same (there are 1000's of .sh's and ID's combination in the environment). ...
5
votes
0answers
113 views

Is it possible to make ls ignore Windows hidden files?

I'm using the GnuWin32 libraries on a Windows 7 machine. I do not like that the ls command shows NTFS hidden files. I've found two methods to hide these files. One solution is to mount the partition ...
0
votes
4answers
3k views

Single line command to cat last file in ls -lrt output? [duplicate]

System log files are serialized and I use ls -lrt to show me the most recent file. I then cat that file. This requires typing a long serial number each time. How can I cat the last file appearing in ...
4
votes
1answer
135 views

ls -l numbers between the size and the group

when I run ls -l /dev/null /dev/zero /dev/tty I get: crw-rw-rw- 1 root root 1, 3 Aug 9 09:05 /dev/null crw-rw-rw- 1 root tty 5, 0 Aug 9 09:05 /dev/tty crw-rw-rw- 1 root root 1, 5 Aug 9 09:05 /dev/...