Linux Basics
Bash Shell
- The default user interface for most Linux distributions.
- Every Linux user has a unique home directory.
Home Directory (~
)
- The
~
symbol represents the home directory of the current user.- For example,
/home/compsec
is equivalent to~
.
- For example,
Linux Path
Path Representations
There are two ways to represent paths in Linux:
-
Absolute Path
- Specifies a location starting from the root directory (
/
), regardless of the current working directory. - Example:
/home/user/file1.txt
- Specifies a location starting from the root directory (
-
Relative Path
- Specifies a location relative to the current working directory.
.
represents the current working directory...
represents the parent directory.- Example:
./file1.txt
or~/file1.txt
Linux Command List
Command | Description |
---|---|
pwd | Print current working directory |
ls | List contents of the current directory |
touch [new filename] | Create a new empty file |
mkdir [new directory name] | Create a new directory |
cd [location] | Change the current directory |
cp [source] [destination] | Copy source file to destination |
cp -r [source] [destination] | Copy directories recursively |
mv [source] [destination] | Move or rename source file to destination |
rm [filename] | Remove a file |
rm -r [directory name] | Remove a directory and its contents recursively |
Linux Commands in Bash Shell
Examples of Basic Commands
-
mkdir (make directory)
Create a new directory named
temp
:user@XXX:~ $ mkdir temp
-
cd (change directory)
Change to the newly created temp directory, and then back to the home directory:
user@XXX:~ $ cd temp
user@XXX:~/temp $ pwd
/home/user/temp
user@XXX:~/temp $ cd ~
user@XXX:~ $ pwd
/home/user -
ls (list)
List contents of the current directory and its detailed view:
user@XXX:~ $ ls
temp
user@XXX:~ $ ls -l
drwxrwxr-x 3 compsec compsec 4096 Jun 1 00:00 temp -
touch and rm (create and remove files)
Create a new file named file and then remove it:
user@XXX:~ $ touch file
user@XXX:~ $ ls
file temp
user@XXX:~ $ rm file
user@XXX:~ $ ls
temp
user@XXX:~ $ rm -r temp
user@XXX:~ $ ls
By understanding these basic Linux commands and concepts, you will be better equipped to navigate the Linux environment and manage files effectively.