If you use Linux [or bash in Windows], it is helpful to know some basic quick commands. If you use Arch Linux, then you already know everything.
CAT
I often use cat to view the contents of a file (for example a document or script). It's useful because it is quick and it doesn't open the file to edit, so there is no risk of editing by mistake.
$ cat
insert_filename_here
$
The cat command lists the file contents to the terminal window.
Above, I used the cat command to list the contents of a simple CPUtemp.sh script.
CD
I use cd for navigationg around directories. My most common use case would be to navigate up one folder, which you do by adding two full stops to the command.
$ cd |
..
|
$ |
The cd .. command navigates up one folder.
|
Above, I listed the folder contents using the ls command, then entered the scripts directory using cd scripts. Then, the cd .. command to go back up one folder level, pwd prints the current directory path -so the ls command again shows that you are back in the home directory.
CURL
Curl is most commonly used as a command to retrieve a file from a URL. You can curl a website and it will output the contents of that page in the terminal window.
$ curl
insert_url_here
$
The curl command lists the website page contents to the terminal window.
Above I used curl to list my website index html code. You can get the same output by viewing the page source of the site using any web browser, just CTL-U.
CURL -O
Curl is also useful for downloading a file with a progress bar, such as via web or ftp.
$ curl |
-C - -O http://speedtest.tele2.net/10MB.zip
|
$ |
The -O option shows download progress; -C - option resumes download progress.
|
Normally you can run curl with just the -O (uppercase O will retain the same filename) option to see the progress bar in the terminal window. Adding the -C - option is useful when downloading larger files, because if the download stops for any reason, it will automatically resume.
As you see I hit CTL-C to cancel the download before it finished, when I ran the command again with the added -C - option, it resumed the download, rather than start from scratch.
CURL -L
L here stands for location. If the destination server reports that the requested URL has a different location, this flag allows curl to reattempt the get on the new page.
$ curl |
-L insert_url_here
|
$ |
The curl -L command instructs curl to follow any redirect to a destination.
|
Above, the 'test' page does not exist. Using the -L option, curl will follow the NGINX redirect to my custom 404 page, just as if you tried reaching the test page from a browser.
I should really have just made this entire post about curl, such is the vast amount of uses it has. Stay tuned for more useful linux commands and examples in future posts.
back