Lately, I started learning commands lines. I mean, I used npm install
or gulp
, but no more.
So I started using commands lines and I have to say that I like it. A lot.
I wanted to share with you what I learned.
cd
The cd
command is used to change the current directory.
cd stand for change directory
cd path/of/directory
To move up by one directory you can hit
cd ..
Source
ls
The ls
command list all files of a type other than directory, found in the current directory.
ls stand for list segments
ls
man
The man
command display the online manual pages. We can specify a section as parameter. The section is normally the command, function or file name.
man stand for manual.
man name_of_command
To exit the manual you can hit
q
,:q
,Q
,:Q
orZZ
.
mkdir
The mkdir
command is used to create a new directory. The directory would be create in the current directory.
mkdir stand for make directories.
mkdir name_of_directory
rmdir
The rmdir
command is used to remove an empty directory.
rmdir stand for remove directories.
rmdir name_of_directory
We can pass an -p
option. In this case each directory argument will be treated as a single path and will be removed if they are empty.
rmdir -p name/of/directory
mv
The mv
command is used to move a file into a given directory.
mv stand for move.
mv name_of_file name/of/directory/destination/
open
The open
command is used to open a file or a directory
open name_of_file
I know, it's very basic, but you have to start somewhere. 😅
I created a Gist where I add what I learn.
And you, what are your favorite commands?
Oldest comments (30)
I really do love
tar -xfv test.tar
andls -lisa
If I understand correctly, you can chain options?
-xfv
means-x
, then-f
, then-v
, is it correct?This is correct (of most commands)! Some more complex ones can't be chained.
For example, you can't chain
--this-is-an-arg
and--this-too-is-an-arg
but individual letters are usually fine.I typically use ls -lart :) (the a isn't necessary but it is appropriate ;) )
I understand why you do that and it spoils it a little to add a letter - but my only common use case apart from a normal
ls
isls -larth
.If you find your self puzzled by the various archive extensions then this is for you. Linux CLI unpack unification script.
pastebin.com/wNCP166T
(Excuse the shameless plug btw)
Oh yeah, good to know, thanks!
If you're finding yourself attacking those annoying commands often, consider setting an alias for them!
Instead of typing
ls -AbcClhoG
, you could alias all that intoll
.First thing's first, assuming you're using
bash/sh
and notzsh
or variants (usewhich $SHELL
to figure that out!), runnano ~/.bashrc
to start editing your config for the shell.You'll then want to add an alias at the bottom now, using
alias ll="ls -AbcClhoG"
. Easy!Ctrl + C, Y, Y
to save and exit nano, and you'll want tosource ~/.bashrc
or make a new tab in Terminal to reload your settings.You can run any commands and name them however you want - even chaining them as you go.
command & command
will run them concurrently, whilstcommand && command
will run each individually assuming the last command succeeds.command &
will leave the task running indefinitely, so be careful (you can alwaysCtrl + C
out of it).Or you can press
Ctrl + Z
after you docommand &
to run it as a background job.I think
cat
andwhich
are extremely usefulOh
which
command is very useful indeed, especially on macOS where paths are hidden. Thanks, I discovered!Using
open
like that is an OS X/macOS thing -- the FreeDesktop.org standard most Linux distributions adhere to is to usexdg-open
.On Linux, the
open
command handles virtual terminals.Oh thank you, I didn't know. I note it
Nice post! Just a note though,
open
command is a little different between Mac OS and Linux distributions. Linux equivalent isxdg-open
.Edit: You guys already noticed it :(
The find command is one of the most useful on your toolkit
find . -exec cp {} . \;
(Recusevely find all files in a path and copy to the root)
Although you should really be using fd
save yourself.
unlearn rmdir.
now.
There's something wrong with
rmdir
?nope, nothing at all
my bad
I saw "rmdir" and read "rm -rf"
rm -rf
does incredible and irreparable damage except you have backups handy.You can't restore a backup if you
rm -rf /
.Exactly. You just wiped out the entire system..
Well except if you have an external backup of some sort. 😏
grep
is awesome way to search for stuff.Particularly when combined with
|
operator to chain stuff.For example,
ls | grep my_file.txt
Awesome start Jeremy. When I played with Unix terminal for the first time, I made a major mistake which was not going over the basics.
Add these especially if you are in a directory
cd ..
takes you backcd -
takes you to the previous directoryls -sh
lists the files/directories with their sizesls -l
lists the details including permissions.There are lots more, but add these to yours
Have fun in your journey!