Advanced Beginner Command Line Commands

January 9th, 2014

terminal

Just like the title suggests, lets take a look at some slightly more advanced beginner command line commands that will help you out as you venture further into a CLI based workflow.

If you missed the first instalment of this series, just head over to the first post “Get comfortable on the Command Line” and take a quick peak.

man

To start with, lets look at the man command. If you want to find out more about a command, like the description of the command, flags, etc use the man command.

$ man ls

It is that simple, it will explain all the flag options, offer tips sometime, and also suggest other commands that might be of use. You can even man the man command of course! So meta.

mv

Next lets look at mv, this command is used to move files, but more often then not I use it to rename files. For example you could move a file from one location to the next like such:


$ mv chapter1.txt chapters/chapter1.txt

Where your first argument is the source, and the second is the target. If you ran ls on your directory you would see that there is no more chapter1.txt but running ls chapters will reveal the file moved!

Using this same command you can also rename your files. Say you have a file chaptr1.txt and you are like

“dam, speeled that wrung”

Using the mv command you can set the source to the current filename and the target to the new name.


$ mv chaptr1.txt chapter1.txt

Again if you ran the ls command you would see the filename changed!

cp

The cp is just used for copying files, much like mv it takes two arguments, and source and a target. If we wanted to copy our chapter1.txt file and start say chapter2.txt.


$ cp chapter1.txt chapter2.txt

Now you have just copied the file. Any information that was in the source will be in the target. The chapters example might not make the most sense, but I hope you get the idea.

touch

One important command to know is the touch command. touch is actually used to change the modification time of a file, you know when files say “Last modified…”, well one use of touch is that if the file does not exist it will create it!


$ touch app.js

Will create a new blank file. How do you know it is a blank file, besides the fact that it is new…? Well lets print the contents to the screen with the cat command!

cat

The cat command prints the contents of a file to the screen. The usage, I hope by now, is how you might imagine. Command followed by the source file.


$ cat app.js

If the file is empty nothing will show up, if there is something in there, it will be printed to the screen. Pretty simple stuff. Two last commands that I will mention but not go over are head, which prints the first few links of the file, and less which prints the last few lines of file.

Using these commands along with the commands from my first post should get you moving around the command line feeling a little bit better. If you have every shied away from a project that required something like Grunt, NPM or insert new tool here. Hopefully you will now have some more confidence to jump right in and get dirty.


Warning: count(): Parameter must be an array or an object that implements Countable in /home/ryanch6/public_html/wp-includes/class-wp-comment-query.php on line 405
  • contatovitormelo

    Thanks

  • Sean Snyder

    Good post. Another helpful command is grep. “grep -i resolver bower.json” This will search case insensitive for resolver in the bower.json file. You can also use it with the pipe command, ls -l | grep -i readme.