You can use the “rm” command to remove a file. For example, the following command removes the file “file.txt”:
rm file.txt
Utilities for Developers
How to read, write and manipulate files using shell scripts.
You can use the “rm” command to remove a file. For example, the following command removes the file “file.txt”:
rm file.txt
You can use the “ls” command to list the files in a directory. For example, the following command lists the files in the current directory:
ls
cp is a Linux shell command to copy files and directories.
You can use the “cp” command to copy a file. For example, the following command copies the file “file.txt” to the file “copy_file.txt”:
cp file.txt copy_file.txt
You can use the “cp” command to copy a directories.
Copy from source to dest
$ cp [options] source dest
cp command main options:
option | description |
---|---|
cp -a | archive files |
cp -f | force copy by removing the destination file if needed |
cp -i | interactive – ask before overwrite |
cp -l | link files instead of copy |
cp -L | follow symbolic links |
cp -n | no file overwrite |
cp -R | recursive copy (including hidden files) |
cp -u | update – copy when source is newer than dest |
cp -v | verbose – print informative messages |
You can use the “mv” command to rename a file. For example, the following command renames the file “file.txt” to “new_file.txt”:
mv file.txt new_file.txt
You can use the “echo” command with the “>>” operator to add content to a file. For example, the following command adds the string “one more line” to the file “file.txt”:
echo “one more line” >> file.txt
You can use the “echo” command to write to a file. For example, the following command writes the string “example” to the file “file.txt”:
echo “example” > file.txt
You can use the cat command to read the contents of a file. For example, the following command reads the contents of the file “file.txt” and displays it on the screen:
cat file.txt