The “ls” command is probably the most generally used command to listing recordsdata and directories in a listing in Unix-like techniques. Nevertheless, there are different methods to listing listing contents with out utilizing ls command. As it’s possible you’ll know, many different packages exists to the preferred and extensively used present Linux packages. We’ve already posted about good alternate options to ‘high’, alternate options to ‘du’ command and alternate options to ‘man’ pages. Right now, on this tutorial, we are going to see 10 alternate options methods to listing the contents of a listing with out utilizing “ls” command in Linux.
Listing Listing Contents With out Utilizing ls Command
Often, a lot of the Linux customers use ls command to listing recordsdata and directories in a listing. For instance, we are able to use the next command to show the contents of a listing named ostechnix.
$ ls ostechnix/
That is how we listing recordsdata and directories. Nevertheless, there are methods to do that. As of now, I do know the next ten strategies solely. If I come throughout another higher methodology, I’ll add them too. Additionally, if you recognize different methods to do that, please tell us within the remark part beneath.
1. Listing recordsdata utilizing echo command
The echo command is mostly used built-in command that’s utilized in shell scripts and batch packages to print the given arguments. You possibly can go any textual content/string as an argument and the echo command will show them on normal output or file. This command isn’t just for printing the given arguments but additionally can be utilized to listing recordsdata.
To listing recordsdata utilizing within the present listing, simply kind:
$ echo *
To listing all recordsdata down one degree, use this command:
$ echo */*
To listing hidden recordsdata, run:
$ echo * .*
For extra particulars, refer man pages.
$ man echo
As you may see, the echo command will solely show recordsdata, not directories. No drawback, the next strategies covers the way to listing each recordsdata and directories. Learn on.
2. Listing recordsdata and directories utilizing printf command
The printf command is used to format and print textual content. This command will print the given arguments in keeping with the given format, or execute in keeping with given possibility.
To listing the contents of the present listing utilizing printf command, run:
$ printf ‘%sn’ *
Not like the “echo” command, the print command will show each recordsdata and directories.
For extra particulars, refer man pages.
$ man printf
three. Listing recordsdata and directories utilizing dir command
The dir command is yet one more Linux command to show the contents of a listing. It’s usually thought-about to be Home windows equal, however works in Linux just about the identical method.
To listing the present listing contents, run:
To listing the contents of a particular listing, simply go its path as an argument like beneath.
$ dir /residence/sk/ostechnix
To listing all contents together with hidden recordsdata:
$ dir -a
Refer man pages to know extra about dir command.
$ man dir
four. Listing recordsdata and directories utilizing discover command
The discover command is used to seek for recordsdata in a listing hierarchy. Not only for file looking, we are able to additionally use discover command to listing listing contents like beneath.
$ discover -maxdepth 1
$ discover .
As you may see, the primary command lists all recordsdata and directories down one degree within the present listing whereas the second command lists all recordsdata and directories recursively.
You possibly can listing the contents of a particular listing as properly.
$ discover dir1/
Really helpful learn:
5. Listing recordsdata and directories utilizing stat command
The stat command is used to show file and filesystem info. Utilizing this command, we are able to discover file properties comparable to dimension, permissions, creation and entry dates amongst others.
To listing recordsdata and directories utilizing “stat” command,
$ stat -c ‘%A %n’ *
As you may see, the stat command not simply lists the contents of the present listing, but additionally the permissions. It’s helpful if you wished to view the listing contents together with the permissions.
Verify man pages for extra particulars about stat command.
$ man stat
6. Listing recordsdata and directories utilizing grep command
The grep command is used to go looking textual content recordsdata with common expressions. We wrote an in depth information about grep utilization some time in the past. Verify the next hyperlink to know extra about grep command and its variants.
To listing the listing contents utilizing grep command, simply run:
$ grep -l ‘.*’ ./*
7. Listing recordsdata and directories utilizing lsattr command
The lsattr command is used to listing the attributes of recordsdata and directories on Linux.
To listing recordsdata and directories in a present working listing, use lsattr command:
$ lsattr ./*
As you see within the output, the lsattr command shows contents simply down one degree. In different phrases, it received’t show any sub-directories and its contents and hidden recordsdata.
Verify man pages for particulars about lsattr command.
$ man lsattr
eight. Listing recordsdata and directories utilizing getfacl command
The setfacl and getfacl are most helpful and essential instructions each system admins should know to set Entry management lists(ACLs) of recordsdata and directories.
To view the listing of recordsdata and directories in a present listing, simply run:
$ getfacl ./*
One factor I like most about this command is it not simply lists the listing contents, but additionally different helpful particulars comparable to,
proprietor of the file/listing,
group which has entry to it,
entry rights to proprietor, group and others.
9. Listing recordsdata and directories utilizing for loop
One other methodology to listing listing contents is to make use of for loop. I examined this in BASH and it labored simply wonderful as anticipated.
$ for i in *; do echo $i; accomplished
As you see within the above output, we are able to listing the present listing contents utilizing for loop.
10. Listing recordsdata and directories utilizing Vim editor
Final however not least, Vim editor will also be used to listing recordsdata and directories. As it’s possible you’ll already know, all the pieces in Linux is a file. So technically talking, a listing is a file that accommodates a listing of recordsdata and/or sub-directories.
To listing recordsdata and directories of present listing utilizing Vim editor, use the next command:
$ vim .
Please be aware that dot (.) on the finish.
To listing the contents of a particular listing, do:
$ vim ostechnix/
Simply use the UP/DOWN arrows to navigate by way of the listing. To listing a sub-directory contents, simply place mouse cursor on it and hit ENTER.
And, that’s all for now. I don’t know any sensible use circumstances for these strategies proper now. The ls command comes pre-installed in virtually all Unix-like working techniques, so you may merely use it to simply show listing contents. Simply in case the “ls” command isn’t accessible in your system, use these alternate options methods to ls with out “ls” command.
Extra good stuffs to return. Keep tuned!
Thanks for stopping by!
Assist us that will help you:
Have a Good day!!