In: Computer Science
In Linux system, explain step by step what the following commands do:
mkdir test
cd test
cp /etc/fstab .
ls
ls -l
touch foo ./-l
ls
ls -l
Then execute the following command:
ls *
Explain the result. What is the problem?
Execute the following command:
rm *
Explain the result. What is the problem?
Modify the "rm *" command so that it works correctly. Explain your solution.
mkdir test:
mkdir is one of the basic Unix commands which allows you to create new directories. It can take one or more directory names as command line parameters.
mkdir test will create a directory named test.
cd test:
cd is nothing but change directory. cd test will go to the directory test.
cp /etc/fstab:
cp basically copies file. Above syntax is wrong, it should be
ls:
lists your files in the presend directory.
ls -l:
ls command lists the files in 'long format', which contains some extra information about the file. e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
touch foo ./-l :
touch command basically is used to create file without any content. It simply creates an empty file.
Above command will create 2 files in same directory, foo and -l.
ls *:
As explain above ls is to list the files in the presend directory, whereas * is used to search the matching file in directory.
But ls * will simply list down all the files present. Instead if you are tying to seach some particular file say foo.
Then you can search it like this ls *o , this will match all the files those ends with character o.
rm *:
rm command is used to remove objects such as files, directories. In your case rm * can be a dangerous thing to do as * will match all the file/folder names and rm will delete them all. Instead you can try this rm *o : delete files those ends with character o.
Hope I made things clear to you. Enjoy!!!!!!!!