Linux study notes: basic instructions ls, cd

#The learning content comes from Mofan python:linux tutorial

cd command 

Using the cd command, we can easily switch to different folders in Terminal. Want to go to the Documents folder from Home? Just type the following command.

~$ cd Documents/ and
then you will see it jump out of this thing on the next line, the ~/Documents in front of the $ means that you are now in the Documents folder. The command you want to execute now will be in this directory take effect.

~/Documents$
Next, let's list some other commonly used cd commands.

1 Return to the previous directory

~/Documents$ cd ..

~$

2 go to subfolder

~$ cd Documents/folder1/
~/Documents/folder1$
3 returns the directory you were just in

~/Documents/folder1$ cd -
/home/kumata
~$
4 go back up twice

~/Documents/folder1$ cd ../../
~$
5 to Home

~/Documents/folder1$ cd ~
~$
6 To go anywhere on the computer, all you need is an absolute path

~$ cd /home/kumata/Documents/folder1
~/Documents/folder1$


ls command


We can move around in the files on the computer now, it's not interesting, then we move to a place and see what's in that place. (It feels like a hacker is peeping at other people's files, haha).

I put a folder (folder1) and a file (file1) in the Documents directory. We import the directory to Documents, and then use ls (short for list) to see what's inside.

 

~/Documents$ ls
file1 folder1
Let's look at other ways of using ls.

1 Output details -l (short for long). This command will print out the file's permissions (-rw-rw-r-- we'll talk more about this later), username, file size, modification date, file name

~/Documents$ ls -l
total 4
-rw-rw-r-- 1 kumata kumata 0 Oct 12 07:38 file1
drwxrwxr-x 2 kumata kumata 4096 Oct 12 07:26 folder1
2 -a (short for all) show all Files. Hidden files (starting with .) are also shown here

$ ls -a
. .. file1 folder1 .hidden_file
3 -lh (human), direct -l is not convenient for human viewing, this command is for the convenience of human viewing. Note that the file size here uses K, MB, GB, etc. generalize

$ ls -lh
total 4.0K
-rw-rw-r-- 1 kumata kumata 0 Oct 12 07:38 file1
drwxrwxr-x 2 kumata kumata 4.0K Oct 12 07:26 folder1
4 There are many other functions, we can pass --help to view

$ ls --help

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024686&siteId=291194637