syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

You are here: Linux101 > linux101_cclud_folder
Question:
In Linux101 how to CCLUD Linux Folders?

To do Machine Learning on Linux I need to be skilled at CCLUD of folders.

To create a folder I use the mkdir command.
dan@feb /tmp $ 
dan@feb /tmp $ mkdir folder1
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder1
total 16
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:33 .
drwxrwxrwt 27 root root 12288 Feb 11 20:33 ..
dan@feb /tmp $ 
dan@feb /tmp $ 
In the above demo I use ls to confirm the folder exists. So the ls command is useful; I use it to list both folders and files. Now we know how to create and list a folder which are two verbs out of five.

Three commands are available to copy a folder: cp, rsync, and tar
dan@feb /tmp $ 
dan@feb /tmp $ 
dan@feb /tmp $ cp -r folder1 folder2
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder2
total 16
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 .
drwxrwxrwt 28 root root 12288 Feb 11 20:44 ..
dan@feb /tmp $ 
dan@feb /tmp $ 

I can use rsync to copy a folder:

dan@feb /tmp $ 
dan@feb /tmp $ rsync -a folder2 folder3
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder3
total 16
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 .
drwxrwxrwt 29 root root 12288 Feb 11 20:46 ..
dan@feb /tmp $ 
dan@feb /tmp $ 

I can use tar to copy a folder into a tar-file:

dan@feb /tmp $ 
dan@feb /tmp $ tar cf folders.tar folder1 folder2 folder3
dan@feb /tmp $ 
dan@feb /tmp $ mkdir folderA
dan@feb /tmp $ 
dan@feb /tmp $ cd folderA
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ tar xf ../folders.tar
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 30 root root 12288 Feb 11 20:52 ..
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:33 folder1
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder3
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 

I can use tar to backup my work to a single tar-file.
Then I can put a date in the name of the tar file.
Then I can copy the tar file to box.com

Now we know how to create, copy, and list a folder.

Linux gives me several commands to update a folder: chown, chgrp, and chmod

dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 30 root root 12288 Feb 11 20:52 ..
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:33 folder1
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder3
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 


Notice that I have three folders.
The chown and chgrp commands are usually done from root account:

dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ su
Password: 
root@feb:/tmp/folderA$ 


I deleted the fox account in a previous demo.
Now I create the fox account.

root@feb:/tmp/folderA$ useradd -m -s /bin/bash fox
root@feb:/tmp/folderA$ 

Now I use chown command to change ownership of folder1 to fox:

root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ chown fox folder1
root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 31 root root 12288 Feb 11 21:05 ..
drwxrwxr-x  2 fox  dan   4096 Feb 11 20:33 folder1
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder3
root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ 


Notice above that folder1 is in the dan group.
I use chgrp to put folder1 in the fox group:

root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ chgrp fox folder1
root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 31 root root 12288 Feb 11 21:05 ..
drwxrwxr-x  2 fox  fox   4096 Feb 11 20:33 folder1
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder3
root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ 
root@feb:/tmp/folderA$ exit
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 

In the above output Linux shows me permission bits on the left side.

I can change those bits using the chmod command.

Notice that the .. folder has these permission bits:

drwxrwxrwt

I use chmod below to update folder3 so it has the same bits:

dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ chmod 1777 folder3
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 30 root root 12288 Feb 11 21:26 ..
drwxrwxr-x  2 fox  fox   4096 Feb 11 20:33 folder1
drwxrwxr-x  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxrwt  2 dan  dan   4096 Feb 11 20:44 folder3
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 


I use chmod below to update folder2 so it has fewer permission bits:

dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ chmod 700 folder2
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ ls -la
total 28
drwxrwxr-x  5 dan  dan   4096 Feb 11 20:52 .
drwxrwxrwt 30 root root 12288 Feb 11 21:26 ..
drwxrwxr-x  2 fox  fox   4096 Feb 11 20:33 folder1
drwx------  2 dan  dan   4096 Feb 11 20:44 folder2
drwxrwxrwt  2 dan  dan   4096 Feb 11 20:44 folder3
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 
dan@feb /tmp/folderA $ 

Now that folder has fewer permissions.
For example if I login as fox, I have permission to put a file in folder3
but I have no permission to put a file in folder2.

Homework: Does dan have permission to put a file in folder1?

Now we are at the end of the CCLUD verbs for a folder. How do I delete a folder?
dan@feb /tmp $ 
dan@feb /tmp $ 


Linux allows me to rmdir a folder if the folder is empty:

dan@feb /tmp $ 
dan@feb /tmp $ mkdir folder4
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder4
total 16
drwxrwxr-x  2 dan  dan   4096 Feb 11 21:41 .
drwxrwxrwt 31 root root 12288 Feb 11 21:41 ..
dan@feb /tmp $ 
dan@feb /tmp $ 
dan@feb /tmp $ rmdir folder4
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder4
ls: cannot access folder4: No such file or directory
dan@feb /tmp $ 
dan@feb /tmp $ 

Yay! rmdir works.

Now I put a file in folder4 and try again:

dan@feb /tmp $ 
dan@feb /tmp $ mkdir folder4
dan@feb /tmp $ 
dan@feb /tmp $ touch folder4/hello.txt
dan@feb /tmp $ 
dan@feb /tmp $ rmdir folder4
rmdir: failed to remove ‘folder4’: Directory not empty
dan@feb /tmp $ 
dan@feb /tmp $ 
dan@feb /tmp $ 

To delete folder4 I need to use rm which is the command we used to delete files:

dan@feb /tmp $ 
dan@feb /tmp $ rm -rf folder4
dan@feb /tmp $ 
dan@feb /tmp $ ls -la folder4
ls: cannot access folder4: No such file or directory
dan@feb /tmp $ 
dan@feb /tmp $ 


CCLUD of Packages is the next topic of Linux101:
linux101_cclud_pkg


You are here: Linux101 > linux101_cclud_folder
syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me