This monstrosity would list anything in the cwd anything in directory dir1 anything in the directory one above us anything in directory dir2 that ends with. Note that you can use an arbitrary number of arguments and that bash uses the convention that an asterik matches anything.įor example, to list only files with the. It will color directories and files and executables differently, allowing you to quickly scan the contents of your folder. Since you very frequently want to use ls with these flags, it makes sense to alias them: $ ls -al # list all, including dot- files and dirs List in long form all files in the directory, including dotfiles: $ ls -hlt # long form, human readable, sorted by time List in human-readable long form sorted by the time the file was last modified: List in human-readable (bytes will be rounded to kilobytes, gigabytes, etc.) long form: List in long form-show file permissions, the owner of the file, the group to which he belongs, the date the file was created, and the file size: $ ls -1 # list vertically with one line per item If we pass directories to the command as arguments, it will list their contents. Ls ls lists the files and directories in the cwd, if we leave off arguments. If it does exist, we cd into it and it's business as usual. If the user gives an output directory as an argument and the directory doesn't exist, we exit. This can be a useful line to include in a script. Here's the function, which you should paste into your setup dotfiles (e.g. It allows you to scroll through all of your past directories with the syntax: Instead, I like to use a function, cd_func, which I stole off the internet. This is interesting to see once, but I never use pushd and popd. The utilities pushd and popd keep track of the directories you move through in a stack.Įxcept that some_directory is also added to the stack. What if you want to visit the directory you were in two or three directories ago? To return to the directory we were last in: If you want to print your working directory resolving symbolic links:īy convention, if we leave off the argument and just type cd we go HOME: We can save the current working directory in a variable with command substitution:Ĭd /somewhere/else # go somewhere else # do something elseĬd $d # go back to where the script originally started Sometimes in a script we change directories, but we want to save the directory in which we started. To see where we are, we can print working directory, which returns the path of the directory in which we currently reside: Note: Unix-like systems include Linux and Macintosh When this is the case, I make a note of it. I'll briefly introduce each one below along with a quick use case or hint.Ī few of the commands, mostly clustered at the end of the article, are not standard shell commands and you have to install them yourself (see apt-get, brew, yum). Here are my picks for the top 100(ish) commands. These are indispensable but, for anything more than the basics, a vocabulary of about 100 commands is where you want to be. In An Introduction to the Command-Line (on Unix-like systems), which I'll borrow heavily from in this article, we covered my subjective list of the 20 most important command line utilities.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |