Introduction to Linux Commands
Copying files
Copies files from one directory /filename to another. From the command prompt recreate test2 directory under test with two files file1 and file2 mkdir test2 cd test2 touch file1 file2 To make a copy of file1 cp file1 copyoffile1 to make a copy of file1 in another directory without changing the name, for ecamole the test diretory which is the parent diretory of test2 cp file1 ../ to make a copy in the test directory with a new name cpfile1 ../anothercopyoffile1
Touch
Creates a file at the command prompt without having to endter data into it. It can also be used to update the modification time of a file
Searching for words in a file using grep
Grep searches for a pattern of characters in a file or multiple files. If the pattern contains white space, it must be quoted. The pattern is either quoted string or a single word, and all other wods following it are filenames. grep sends its outputs to the screen and does not change or affect the input file in any way. From the /home/guest/test directory create a file called testfile.tct and add the following text; This is a test file created within practical 2 of limux administration class. We wil use this fule as an input file to demostrate the use of: the grep command. We will search for one word occurrences and pattern occurrences using quotes Save the file grep "linux Administration" testfile.txt Case sensitive
Removing Directories
Lets say we want to remove or delete the file renamedfile.txt. we would use the rm -i command. rm -i renamedfile.txt // remove file interactively have to press y to confirm deletion redir - removes directories if empty, otherwise it will come back with a message
mv filename1 filename2
Moves "filename" to different location or renames files.
Copy Directories
Use the -R argument to cpy diretories, subdiretories and files. for example, to copy test2 an all its contents to a directory called /tmp type cp -R test2 /tmp
CAT redirect output to new file
cat example1 > newfile
Concatenate CAT
cat short for concatenate does a number of functions 1. Concatenates two files together 2. displays the contents of file on screen without using an editor. 3. creates single or multiple files 4. redirects output in terminal or files if you create two filles called example 1 and 2 using vim editor if you ran cat example1 it would show you the contents of the file.
returning to home directory
cd.
Clear Console
clear
Hostname
hostname What is the hostname of your machine hostnamect1
Man or info
man pages displays all information regarding all comands available with Cent0S 7. Type man with the name of the command with which you want help on. q to quit man pages
Moving a file
mv "filename with extension" "directory location" mv File23.txt test
Renaming a file
mv file1.txt file23.txt Execute a ls command to check
Moving and renaming a file at one time
mv myfile.txt /test/renamefile.txt
Moving directories
mv subtest ../backup
Delete or remove all files within a directory
rm * Asterisk * is used as a wild card and means everything within directory. Note the test 2 directory is still intact If we wanted to remove test2 and its contents then we must move up a level to the test directory using cd .. and then we use the following command rm -rf test2