Situatie
Solutie
We use the Linux ls
command every day without thinking about it. That’s a pity. Pay it some attention, and you’ll find many useful options — including some you should add to your command-line arsenal.
ls Lists Files and Directories
The ls
command is probably the first command most Linux users encounter. Those of us who hang around the command line use it day in and day out without even thinking about it. That might explain why there is more to this command than most users realize. We list files with it to see what’s in a directory. We list files in long format when we want to look at the permissions on a file. Beyond that, it gets little consideration.
The ls
command is one of those commands with a wealth of options. Perhaps this is part of the problem. There are so many options, how do you sift through them to find the useful ones? And having found them, how do you remember them?
Useful permutations of the ls
command with their strings of options and parameters are the perfect candidates for aliases. In fact, in most distributions, what you think of as the “naked” ls
command is actually an alias. Amongst other things, the type command can be used to show the underlying definition of aliases. Let's look at the definition of ls:
type ls
The --color=auto
parameters are included automatically every time you use the ls
command. This is what provides the different colors for the different file types in the listings.
Simple ls Listings
Everyone who’s spent some time using the Linux terminal knows that, by default, ls
lists the files and directories in the current directory.
ls
If you want to have your listing produced ina single column, use the -1
(one file per line) option:
ls -1
We’ll discuss that weird-looking filename at the top of the listing in a minute.
Using ls on Different Directories
To have ls
list the files in a directory other than the current directory, pass the path to the directory to ls
on the command line. You can also pass more than one directory to ls
, and have them listed one after the other. Here, we’re asking ls
to list the files in two directories, one called “Help” and the other called “gc_help.”
ls Help gc_help
When ls
has listed the contents of the first directory it lists the contents of the second. It prints the name of each directory as it processes them:
Leave A Comment?