SSH command Basic for newbie :b

In linux terminal / server, is a must to memorize some important command so that we can do something more quickly, the command that include navigation commands, move, copy or search. With these command memorized at least we can work on a black screen terminals that: b, and perhaps this post at create a dedicated newbie, if you feel you’ve master please close this web page …. hehehe

Here is a list of some of the more common SSH commands. Many of the following examples have words that are surrounded with brackets ( [ ] ). You will need to make sure that you replace those bracketed words (including the brackets) with the correct substitution. For example, the command to remove a file is rm [filename].

If you had a file named test.html that you wanted to delete, you would take the above command and substitute the filename of the file you wish to delete. The result would be rm test.html.

Navigating

  • /
    • refers to the root directory on the server
  • ./
    • the current directory that you are in
  • ../
    • parent directory of your current directory
  • pwd
    • shows what your current directory is – giving the full path
  • ls
    • lists all the files in your current directory
  • ls -al
    • lists filenames + information
  • ls -aR
    • lists filenames + information in all subdirectories
  • ls -aR | more
    • lists filenames + information in all subdirectories, pausing when the screen becomes full
  • ls -alR > result.txt
    • lists filenames + information and outputs the results to a file
  • ls *.html
    • lists all files ending with .html
  • ls -al/home/usr/sam/
    • lists files + info for /home/usr/sam
  • cd
    • changes you to a new directory
  • cd /
    • changes you to the root directory

Moving, Copying, and Deleting Files

  • mv [old name] [new name]
    • move/rename a file
  • cp [filename] [new filename]
    • copy a file
  • rm [filename]
    • delete a file

Moving, Copying, and Deleting Directories

  • mkdir [directoryname]
    • creates a new directory
  • ls -d */
    • lists all directories within current directory
  • cp -r [directoryname] [new directoryname]
    • copy a directory and all files/directories in it
  • rm -r [directoryname]
    • remove a directory. You will be prompted to answer “Yes” or “No” for whether you would like to delete each file in the directory
  • rm -rf [directoryname]
    • remove a directory and all files and folders in it (no prompting).

Searching Files and Directories

  • find / -name [filename] 2>/dev/null
    • search the whole server for a file
  • find ./ -name [filename]
    • search for a file starting with the current directory
  • grep [text] [filename]
    • search for text within a file

Finding lost files within a computer system with a Linux operating system, with techniques Search for keywords in files

Never had a problem with a file search? We may have experienced this when in need of something while the file name of the file that we will find it forget, while we remember only a few words or writings that exist in the file. In any OS that there is a solution to find the file, not least the linux OS. Inside opreasi linux system we can find the file via commad grep sintax  line. Here’s how we will describe:

Using grep command form (syntax)

grep “text string to search” directory-path
Examples

For example search for a string called redeem reward in all text files located in /home/user/*.extentions directory, use
$ grep “where files keyword on file” /home/user/*.extention
Task: Search all subdirectories recursively

You can search for a text string all files under each directory, recursively with -roption:
$ grep -r “where files keyword on file” /home/user/
Task: Only print filenames

By default, grep command prints the matching lines You can pass -H option to print the filename for each match.
$ grep -H -r “where files keyword on file” /home/user/
Output:


filename.txt: where files keyword on file

To just print the filename use cut command as follows:
$ grep -H vivek /etc/* -R | cut -d: -f1
Output:


filename.txt