Skip to content
0
  • Recent
  • Tags
  • Popular
  • Search
  • ads.txt
  • Recent
  • Tags
  • Popular
  • Search
  • ads.txt
Collapse
Lime-it.us
rickR

rick

@rick
administrators
About
Posts
94
Topics
72
Shares
0
Groups
1
Followers
1
Following
1

Posts

Recent Best Controversial

  • Locating files with the find command
    rickR rick

    Locating files using the find command

    The find command is a powerful utility that allows the user to find files located in the file system via criteria such as the file name, when file was last accessed, when the file status was last changed, the file’s permissions, owner, group, size.


    Find a file “foo.bar” that exists somewhere in the file system

    find / -name foo.bar -print

    On most platforms the -print is optional, however, on some systems nothing will be output without it. Without specifications find searches recursively through all directories.


    Find a file without searching network or mounted file systems

    find / -name foo.bar -print -xdev

    This is useful if you have network drives that you know the file would not be located on. “-mount” does the same thing as “-xdev” for compatibility with other versions of find.


    Find a file without showing “Permission Denied” messages

    find / -name foo.bar -print 2>/dev/null

    When find tries to search a directory or file that you do not have permission to read the message “Permission Denied” will be output to the screen. The 2>/dev/null option sends these messages to /dev/null so that the found files are easily viewed.


    Find a file, who’s name ends with .bar, within the current directory and only search 2 directories deep

    find . -name *.bar -maxdepth 2 -print


    Search directories “./dir1” and “./dir2” for a file "foo.bar

    find ./dir1 ./dir2 -name foo.bar -print


    Search for files that are owned by the user “skippie”

    find /some/directory -user skippie -print

    The files output will belong to the user “skippie”. Similar criteria are -uid to search for a user by their numerical id, -group to search by a group name, and -gid to search by a group id number.


    Find a file that is a certain type. “-type l” searches for symbolic links

    find /any/directory -type l -print


    Several types of files can be searched for: Several types of files can be searched for:

    • b block (buffered) special

    • c character (unbuffered) special

    • d directory

    • p named pipe (FIFO)

    • f regular file

    • l symbolic link

    • s socket


    Search for directories that contain the phrase “foo” but do not end in “.bar”

    find . -name '*foo*' ! -name '*.bar' -type d -print

    The “!” allows you to exclude results that contain the phrases following it.

    find becomes extremely useful when combined with other commands. One such combination would be using find and grep together.

    find ~/documents -type f -name '*.txt' \ -exec grep -s DOGS {} \; -print

    Linux Systems Guides

  • Move files to and from server scp command
    rickR rick

    SCP or (secure copy) allows you to move files even entire directories to, or from local and or remote hosts, using the same authentication and securtiy levels as SSH.

    Copy the file “foobar.txt” from a remote host to the local host

        $ scp username@site.com:foobar.txt /local/directory
    

    Copy the file “foobar.txt” from the local host to a remote host

        $ scp foobar.txt username@remotehost.com:/path/to/directory
    

    Copy the directory “foo” from the local host to a remote host’s directory “bar”

        $ scp -r foo username@remotehost.com:/remote/directory/bar
    

    Copy the file “foobar.txt” from remote host “site1.com” to remote host “site2.com”

        $ scp username@site1.com:/remote/directory/foobar.txt \username@site2.com:/remote/directory/
    

    Copying the files “foo.txt” and “bar.txt” from the local host to your home directory on the remote host

        $ scp foo.txt bar.txt username@site.com:~
    

    Copy the file “foobar.txt” from the local host to a remote host using port 1000 (or whatever ssh port your running on)

        $ scp -P 1000 foobar.txt username@site.com:/remote/directory
    

    Copy multiple files from the remote host to your current directory on the local host

        $ scp username@site.com:/remote/directory/\{a,b,c\} .
    
        $ scp username@site.com:~/\{foo.txt,bar.txt\} .
    

    By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed on slower connections. This can be done by using option -c blowfish in the command line.

    $ scp -c blowfish file.txt username@site.com:~
    

    Use the -C option for compression, and a bit of speed. If you have a fast connection you might not notice much of a difference. However it is a bit more CPU intensive due to the algorithms used to generate the encryption.

    Blowfish scp example:

        $ scp -c blowfish -C file.txt username@site.com:~
    
    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Listing directory contents

    ls - To list the contents of a directory

    Usage: ls [flags]

    Example: ls (To list the current directory)

    Example: ls /tmp (To list the contents of /tmp)

    Example: ls -a (To list hidden files)

    Example: ls -l (To list file/directory permissions and file sizes)

    Example: ls -al /tmp(To list all files and permissions in /tmp)

    Example: ls -il (To get the inode number, permissions, owner, file sizes, UID and timestamps of all files in current directory)

    For more information, in a terminal, type man ls

    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Deleting files

    To delete a file you must first have write permission to it. Once you have write permission, in a terminal run:
    rm filename\

    There is no “Recycle Bin” in Linux so once you delete a file, it’s gone for good.

    Being safe, find the files first and actually look at what you will be deleting! find . -type f -name foo\*

    When removing files, you may use an astrix “*” as a wildcard flag to remove certain files, for example if I wanted to remove all files that began with “foo” , I would run:

    find . -type f -name foo\* -exec rm {} \;

    If anyone tells you to run rm -rf / as root, DO NOT LISTEN TO THEM. Running this command will delete all the files/directories on your Linux system. And render the machine completely useless with zero chance of recovery!


    You should not be running as root to begin with! Learn to use a secondary user, and as well the “su” command or “Super User” as general usage dictates.


    Deleting directories
    If you have ownership to the directory and the directory is empty, you can simply type

    rmdir directoryname to remove the directory.

    If the directory is not empty and you wish to simply delete it and all its contents, run:

    rm -rf directoryname\[/code\] Please be careful with the -rf flag, as it will remove everything in the specified directory including sub directories. With root access and the rm -rf command you can wipe out your entire system if you make an error.

    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Editing files
    The default editor installed with most all distros of linux is VIM , or

    vi filename

    Vim is an advanced command line editor, you should consider learning the commands.

    You can however also use nano To edit a file with nano, simply run:

    nano filename

    This will open up the file and allow to you edit the file. At the bottom of the screen you will notice the various commands that you have access to with nano. If you wish to save the file and exit, simply hold down the control key and hit the x key on your keyboard.

    You will be asked to confirm this edit, if you have permissions to do so, once you confirm by typeing y, the file will be edited and nano will exit.

    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Renaming files
    mv - Command used to move or rename files
    Usage: mv file location
    Usage: mv filename::newfilename

    Example: mv tmp/site-logo.png /tmp/lime-it.png

    Read the manual: man mv


    Moving files
    mv - Used to move or rename files
    Usage: mv file location (to move)

    Example:mv index.html /var/www/index.html

    For more information, in a terminal and read the manual pages, type: man mv

    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Downloading a file using the terminal command wget

    First cd to the tmp directory

    cd /tmp

    Example: wget http://news.lime-it.us/uploads/system/site-logo.png


    Copy files

    cp - Used to copy files or directories from one location to another. We can use the above example for this.

    Example: cp /tmp/site-logo.png /var/www/httpdocs

    [as httpdocs is your root web directory]


    To move ALL files from one directory to another:

    Example: cp /tmp/files/* /var/www/httpdocs

    (the “*” tells the machine to copy everything in /tmp/files to /var/www/)


    Check your man pages for more information on the cp command**

    man cp

    Linux Systems Guides

  • Basic Linux Terminal Commands
    rickR rick

    Adding a user
    While logged in as root, type in the shell:

    replace username with the username you wish

    adduser username
    

    Deleting a user:
    While logged in as root, type replace username with the user name you wish to delete.

    userdel username
    

    Change login password
    To set the password for a specific user, replace username with the name of the user. By typing simply:

      passwd username
    

    To change the current password for the user you are logged in as:

    passwd
    

    Change directories

    cd - Used to Change Directories

    Usage: cd /[directory]
    Example:

    cd /tmp
    

    Example:

    cd ../
    

    (moves back one directory)

    Move to your home directory:

    cd
    

    Check the man pages for more info:

    man cd
    
    Linux Systems Guides
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post