Basic Command Line In Kali Linux

The Linux command line is a powerful tool for managing files, directories, and system operations. In Kali Linux, these commands are essential for navigating the filesystem and performing tasks during penetration testing. This guide covers basic commands like pwd, cd, and ls, along with tools for creating, moving, and removing files, helping you efficiently manage your Linux environment.


Table of Contents
  1. Understanding Your Current Directory: pwd
  2. Changing Directories: cd
  3. Listing Directory Contents: ls
  4. Creating, Renaming, Moving, and Removing Files and Directories
  5. Finding Commands: The PATH Variable
  6. Checking Command Locations: which and type
  7. Display Information: echo
  8. Summary of Commands

1. Understanding Your Current Directory: pwd

  • The pwd command stands for Print Working Directory.
  • It shows your current location in the filesystem.

Example:

$ pwd
/home/kali

In this case, the user is currently in the /home/kali directory.


2. Changing Directories: cd

  • The cd command stands for Change Directory and is used to navigate the filesystem. This command is used to move between directories, which is essential for managing files and organizing work.
2.1. Go to a Specific Directory:
$ cd Desktop $ pwd /home/kali/Desktop
  • This command changes the working directory to Desktop. After running pwd, it confirms the new location as /home/kali/Desktop.
  • Reason: Use this when you want to work on files stored in a specific folder.
2.2. Go Back to the Previous Directory:
$ cd - $ pwd /home/kali
  • The - option takes you back to the directory you were in before the last cd command. This is helpful when you need to quickly switch back and forth between two locations.
2.3. Move Up One Level:
$ cd .. 
$pwd
/home

Using .. refers to the parent directory (one level up). If you are in /home/kali, this command will take you up to /home.

2.4. Return to Your Home Directory:
$ cd $ pwd /home/kali

Running cd without any argument takes you directly to your home directory. This is a quick way to return to your starting location, no matter where you are.

Important Notes:

  • The current directory is represented by a single dot (.), and the parent directory is represented by two dots (..).
  • Efficient navigation reduces the need to manually search for directories, saving time during tasks.

3. Listing Directory Contents: ls

  • The ls command shows the files and folders in the current directory.
  • If no parameters are provided, it lists the current directory’s contents.

Example:

$ ls
Desktop    Downloads  Pictures  Templates  Videos
Documents  Music      Public

This shows all files and directories in /home/kali.


4. Creating, Renaming, Moving, and Removing Files and Directories

4.1 Create a New Directory: mkdir

Use mkdir to create a folder with the specified name.

$ mkdir test
$ ls 
Desktop Downloads Pictures Templates test
4.2 Rename or Move a Directory: mv

Use mv to rename or move files and directories to a new location or renames them if the destination is in the same directory.

$ mv test new 
$ ls 
Desktop Downloads new Templates
4.3 Remove an Empty Directory: rmdir
$ rm file.txt
$ rmdir new 
$ ls
 Desktop Downloads Templates
4.4 Remove a File: rm

Use rm to delete a file or directory (with -r for directories).

4.5 Copy a File: cp

Use cp to copy files. It Creates a duplicate of a file or directory (use -r for directories).

$ cp source.txt target.txt

5. Finding Commands: The PATH Variable

  • The system uses the PATH environment variable to locate executable commands.
  • Description: PATH is a list of directories where the shell searches for commands.
  • You can check the PATH with:
  • This output lists directories where the system searches for commands.
$ echo 
$PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

6. Checking Command Locations: which and type

6.1 Find a Command’s Location: which
$ whixh ls
/bin/ls
6.2 Identify Command Types: type
$ type cd
cd is a shell builtin
$ type rm
rm is /bin/rm

7. Display Information: echo

The echo the command displays text or variables on the terminal.

Description: Outputs the text or value of a variable to the terminal.

Example:

$ echo Hello, World!
Hello, World!

To show the value of a variable:

$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

8. Summary of Commands

CommandPurposeExample
pwdShow current directory$ pwd
cdChange directory$ cd Desktop
lsList directory contents$ ls
mkdirCreate a new directory$ mkdir test
rmdirRemove an empty directory$ rmdir test
mvMove or rename files/directories$ mv file1 file2
rmDelete a file$ rm file.txt
cpCopy a file$ cp source.txt target.txt
echoDisplay text or variables$ echo $PATH
whichFind the location of a command$ which ls
typeCheck if a command is built-in$ type cd

Mastering these basic commands will help you efficiently navigate and manage files on a Linux system. For more details, you can explore the manual pages of each command by typing man <command> (e.g., man ls).