DEV Community

Cover image for linux - cd,ls,Hard&Soft Link
Nivethithaa Saravanavel
Nivethithaa Saravanavel

Posted on

linux - cd,ls,Hard&Soft Link

Linux Basic Commands — cd, ls

Change Directory (cd)

Command Description Example/Notes
cd /home/userName Moves to the user’s home directory.
cd ~/ Shortcut for /home/username.
mkdir demo Creates a new directory named demo.
mkdir -p abc/cde/demo Creates nested directories recursively.
cd .. Moves out of the current directory (to the parent).
cd ../.. Moves up two levels in the directory hierarchy.
cd Moves directly to the home directory.

List Directory Contents (ls)

Command Description Example/Notes
ls Lists all files and directories.
ls -lstr Lists files with metadata (permissions, size, etc.) in sorted order.
ls -a Shows all files, including hidden ones (those starting with .).
ls *end Lists files ending with “end”. Example: ls *txt shows all files ending with .txt.
ls start* Lists files starting with “start”. Example: ls demo* shows all files starting with “demo”.

Hard link and soft link

Hard Links

ln original_file new_named_file

Explanation:

  • B*oth files point to the same data* on disk.
  • Changes made in one file affect the other.
  • Deleting one file does not affect the other, as the data still exists as long as one link remains

Soft Links (Symbolic Links)

Command:

ln -s original_file demo_file

Explanation:

  • The soft link points to the path of the original file, not the data itself.
  • If the original file is deleted, the soft link becomes broken (it remains but points to nothing).

Aliases

Definition:

An alias is a shortcut that allows you to assign a** short name **to a long command or path.

Example:

alias sh="/home/nive/demo/test/abc/"

Now, typing sh will take you to /home/nive/demo/test/abc/.

Important Notes:

  • This alias works only for the current terminal session.
  • To make it permanent, add it to the ~/.bashrc file, then run:

source ~/.bashrc

To make it permanent, add it to the ~/.bashrc file, then run:

source ~/.bashrc
Command:

ln original_file new_named_file

Command:


bash
ln original_file new_named_file
Enter fullscreen mode Exit fullscreen mode

Top comments (0)