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 youcat- reads the output of a file
To view in which directory are we currently (it will present you with the path):
pwdFor 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/documentsOr we can just move one back:
cd ..Now that we are inside the documents directory, we can use pwd to verify.
Next we can list for and files or directories inside our working directory:
lsThis 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/ruanTo view more information about the files, we can use argument -lah long output, hidden files and human readable:
ls -lahFrom 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 testWe 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 directoryThe 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
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 To delete files, we use the command rm, for example:
rm -f file.txtThe -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/testdirWith echo it returns whatever the argument is, for example:
echo "hello, world"Will output:
hello, worldYou can also redirect output to a file using > for example:
echo "hi" > /tmp/newfile.txtThis will write hi to the file /tmp/newfile.txt (if the file does not exist, it will create it)
While we are here, another command cat reads a file, if you run:
cat /tmp/newfile.txtIt will return whatever is in that file for example:
hiNow if you run this again, but change the text:
echo "bye" > /tmp/newfile.txtThis will overwrite the file, if we use >> it will append, so if we run:
echo "bye, again" > /tmp/newfile.txtAnd we use cat to read that file again, we will get:
bye
bye, again