Published May 16th, 2007 by admin
Linux Commands – Working with Files
In Part 1 of this multi part series we learned about transversing directories and viewing files from the Linux shell.
In this installment we will learn about working with files. Let’s go ahead and open up the terminal and type the following:
cd ~
This will take us to the home directory of the currently logged in user. Now type:
touch test.txt
This will create a blank text file named test. Now type:
mkdir test
This will create a directory in your home directory named test. (Type “ls” to see for yourself) Now lets move the test.txt file into the test directory:
mv test.txt test/test.txt
This tells Linux to move the test.txt file into the test directory inside of you home directory. You can also use the mv command to rename a file as so:
mv test.txt test1.txt
Now lets make a backup of the test.txt file:
cp test.txt text_backup.txt
This tells Linux to copy the test.txt file and name the copy test_backup.txt. Now let’s navigate back into your home directory using:
cd ..
This tells Linux to move up one directory level from where you currently are. Now if we would need to find the test.txt file we just made amongst other files you would type:
find test
That command will list all the files and their locations that meet the search criteria, “test” in this case.
Now let’s clean up the files and folder we made via:
cd test
and then:
rm test*
The above command will remove any file starting with test in the current directory. The “*” character acts as a wild card matching any character(s) that may follow “test”.
Now type:
cd ..
and finally:
rmdir test
The above command will remove the test directory that we created in the home directory.
This concludes part two, Working with Files. Thanks for visiting and tune in tomorrow for our next installment dealing with file ownership and permissions.