emerglines Posted September 7, 2013 Share Posted September 7, 2013 (edited) For some of you, this is a basic command that you use literally all the time, If this is you, then this tutorial isn’t for you. But if you’re new to Linux or just new to the command line “ls” is a command you will get to know very well. At the surface level, ls is a simple command, and if typed in any directory or anywhere on the command line, all it does is list the contents of your current working directory. But if I were to leave it at just that I would have done you no favors at all. In fact, I’m going to tell you some tips and tricks to ls and we might even throw in a grep command if you’re lucky! LS – More Than Meets The EyeLS lists the contents of your current working directory. This is very simple if you have a directory with a few files in it and hard to use if you have a directory with hundreds or even thousands of files in it. Not only that, by default Linux hides all files that start with a dot (.) because Linux interprets these as configuration files, and only power users, or users who really know what they are doing should see these on a regular basis. Simply using the ls command on the command line won’t actually display these dot files and if you’re a Linux beginner this might be frustrating.Think you’re done? Perhaps we have a few other use cases that you didn’t think about. For example, what if you’re looking to list all files that have a file extension of .txt? Or maybe you just want to list all the directories but not individual files? How about if you need to output the standard out results to a text file? Or if you need to see the size details, ownership details, date modified, permissions, and the size in megabyte format? Heck we can even list all the files that are located inside of the files that we’ve just listed (recursive)!!Don’t worry if your mind is blown, then we just need to get to the examples. Your take away? Knowing the ls command will only get you sar far, reading the man page will get you a little farther, and this tutorial will take you even farther than that. Will it teach you everything about the ls command? No, the fact of the matter is that’s why Linux is so deep and flexible. If you think you’ve done it or know it, there is ALWAYS way more to everything, even the most simple commands. This is why Linux is the #1 operating system for servers and UNIX/Linux is found on 90% of all smart phones (iOS is UNIX and Android is Linux). Don’t let it intimidate you–it will only make you smarter.Examples & Use CasesList all files in a Linux directory including hidden (dot) files and directories[[email protected] $] ls -aList files and show permissions, user owner, group owner, last modified/created date[[email protected] $] l ls -l-l stands for “long listing” and will show you all the details important to the Linux system about the Linux file.List all files, and all the files inside of the directories (or just list the folder recursively[[email protected] $] l ls -RList all files, sorted by file size[[email protected] $] l ls -SList only directories[[email protected] $] l ls -dHuman readable – Size in MB or GB[[email protected] $] ls -hSort in alphabetical order by file extension[[email protected] $] ls -X Now Let’s See Some CombinationsList “all” files, in “human readable format” in long detailed format.[[email protected] $] ls -alhList “all” files and output the contents to a text file[[email protected] $] ls -a > contents.txtNOTE: > will create a text file or write over the existing file >> will append to the file if it exists or create the file if it does not.List “all” files but show only those files ending with .txt[[email protected] $] ls -a | grep *.txtThere’s More But Start SimpleTake a look at the man file for LS “man ls” and you’ll see many more options. But at the risk of overwhelming you I just created the most common LS commands/flags with a combination. This is a practical usage guide for beginners on how we use the LS command on a regular basis. 99% of the time this will be all you need, and if you need more, well then you’re not a beginner and this tutorial isn’t for you!Source Edited September 7, 2013 by emerglines Quote Link to comment Share on other sites More sharing options...
TuFaS Posted September 8, 2013 Share Posted September 8, 2013 Thanks 4 Sharing! :rolleyes: Quote Link to comment Share on other sites More sharing options...
tsaqofa Posted January 18, 2014 Share Posted January 18, 2014 Thank you for sharing ..very useful information B) Quote Link to comment Share on other sites More sharing options...
FukenGruven Posted January 18, 2014 Share Posted January 18, 2014 i've tried to install Linux (Ubuntu) twice..both times i was stuck when it kept asking for a terminal response..anyone know what the heck it's asking for?and how i can successfully pass that screen? Quote Link to comment Share on other sites More sharing options...
tsaqofa Posted January 18, 2014 Share Posted January 18, 2014 (edited) i've tried to install Linux (Ubuntu) twice..both times i was stuck when it kept asking for a terminal response..anyone know what the heck it's asking for?and how i can successfully pass that screen?Can you send screenshot related installation problemsIf there is an image may be more obvious to seek a solution Edited January 18, 2014 by tsaqofa Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.