Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active November 28, 2025 14:14
Show Gist options
  • Select an option

  • Save ruanbekker/2b766a9bd141e9f1f28c34ead3273495 to your computer and use it in GitHub Desktop.

Select an option

Save ruanbekker/2b766a9bd141e9f1f28c34ead3273495 to your computer and use it in GitHub Desktop.
Basic Linux Commands

Basic Linux Commands

This will show you some basic commands such as:

  • pwd (shows the current directory)
  • cd (changes directories)
  • ls (lists files)
  • touch (creates files)
  • rm (deletes files and directories)
  • echo - returns text back to you
  • cat - reads the output of a file

pwd

To view in which directory are we currently (it will present you with the path):

pwd

cd

For example if the output is /home/ruan/documents/test, it means we are inside the test directory. We can navigate one directory back, in multiple ways:

cd /home/ruan/documents

Or we can just move one back:

cd ..

Now that we are inside the documents directory, we can use pwd to verify.

ls

Next we can list for and files or directories inside our working directory:

ls

This is the most basic way to list for files or directories. We can use a argument to list what is in a different directory, without changing the paths:

ls /home/ruan

To view more information about the files, we can use argument -lah long output, hidden files and human readable:

ls -lah

From the output:

total 32K
-rw-rw-r-- 1 ruan ruan 2.8K Nov 26 08:30 README.md
drwxrwxr-x 2 ruan ruan 4.0K Nov 28 13:57 test

We can see a file README.md and a directory test and the way we can see if its a file or directory is by viewing:

-rw-rw-r--
drwxrwxr-x (the first bit shows a d which stands for directory

The permissions is not so important now but to touch on it:

drwxrwxr-x

12345678910
drwxrwxr-x

1 - file or directory
2,3,4 - read, write, execute for the given user
5,6,7 - read, write, execute for the group
8,9,10 - read, write, execute for other

-rw-rw-r-- 1 ruan ruan 2.8K Nov 26 08:30 README.md

In the above we can see its a file, the user (ruan) has access to read write, the group also allows read-write, and any other user only has read access

touch

To create files we use the command touch, touch creates files, and the argument is the file that it needs to create:

touch file.txt
# or to create a file at a specific location
touch /tmp/file.txt 

rm

To delete files, we use the command rm, for example:

rm -f file.txt

The -f means that it wont prompt you for confirmation.

The behavior is different where we delete files inside the directories, we get the -r recursive argument. Lets say we want to delete all the files under /tmp/testdir/foo/*

rm -rf /tmp/testdir

echo

With echo it returns whatever the argument is, for example:

echo "hello, world"

Will output:

hello, world

You can also redirect output to a file using > for example:

echo "hi" > /tmp/newfile.txt

This will write hi to the file /tmp/newfile.txt (if the file does not exist, it will create it)

cat

While we are here, another command cat reads a file, if you run:

cat /tmp/newfile.txt

It will return whatever is in that file for example:

hi

Now if you run this again, but change the text:

echo "bye" > /tmp/newfile.txt

This will overwrite the file, if we use >> it will append, so if we run:

echo "bye, again" > /tmp/newfile.txt

And we use cat to read that file again, we will get:

bye
bye, again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment