Site icon NetworkHunt

Basic Command Line In Kali Linux

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

Example:

$ pwd
/home/kali

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


2. Changing Directories: cd

2.1. Go to a Specific Directory:
$ cd Desktop $ pwd /home/kali/Desktop
2.2. Go Back to the Previous Directory:
$ cd - $ pwd /home/kali
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:


3. Listing Directory Contents: ls

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

$ 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).

Exit mobile version