This is the third post in the Linux Series and this post will be about navigating the command line and getting help for commands etc. I will also write about some basic concepts like arguments and such.
Command Arguments
First we need to learn about the command arguments. An argument is a keyword that you type in front of a command to change the output in some way. A command can accept no argument or one or more than one argument.
Everything you type after the command separated by a space is an argument. For exmaple using cd
command to change directory you provide the path or name of the directory to to it to.
Getting help for a command
To get some help about the command in use you type the --help command and press enter. The result will be how the command works and what input or arguments it takes and what the output will be etc.
root@User:/$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default
DIR is the value of the HOME shell variable.
The variable CDPATH defines the search path
for the directory containing DIR. Alternative
directory names in CDPATH are separated by
a colon (:). A null directory name is the same
as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
...
...
Navigation
pwd - Print working directory
It does what its name means, It prints the name of the directory that a user is currently working in.
root@User:/tmp$ pwd
/tmp
ls - List items in the directory
It prints out the contents of the current directory.
root@User:/$ ls
bin dev root run
mnt media tmp etc
boot ... ... ...
if you type -a
argument in front of the ls
command it will print out all the files including hidden ones.
root@User:/root$ ls
root@User:/root$ ls -a
. .. .viminfo .profile .bash_history .bashrc
cd - Change directory
Command to change the directory.
root@User:/$ pwd
/
root@User:/$ cd tmp
root@User:/tmp$ pwd
/tmp
root@User:/tmp$ cd ..
root@User:/$ pwd
/
It works like this cd name-of-directory
. Two dots ..
means to go one step up in the filesystem.
A complete path to the directory can also be typed as an argument. example
root@User:/$ pwd
/
root@User:/$ cd /tmp/some-dir/new-dir
root@User:/tmp/some-dir/new-dir$ pwd
/tmp/some-dir/new-dir
To jump to the home directory of the user just type ~
as the argument to the cd
command.
root@User:/tmp/some-dir/new-dir$ pwd
/tmp/some-dir/new-dir
root@User:/tmp/some-dir/new-dir$ cd ~
root@User:/$ pwd
/
Creating file and directories
Following commands are used to create new files and directories or modify existing files.
mkdir - Make Directory
mkdir is used to make new folders or directories.
root@User:/tmp$ ls
root@User:/tmp$ mkdir new-dir
root@User:/$ ls
new-dir
root@User:/tmp$ mkdir another-new-dir
root@User:/tmp$ ls
another-new-dir new-dir
touch - Create new files
touch command create a newfile with the filename as an argument
root@User:/tmp$ ls
root@User:/tmp$ touch new-file
root@User:/tmp$ ls
new-file
There is also one command called cat
not the animal cat but short form of concatenate that can also create new files and edit them but that command can do much more and I will discuss them more in the next posts.