Helpful Linux Commands

1. Cron

Edit Crontab:

Opens the Crontab for editing, such as adding, removing, or modifying scheduled tasks:

    $ crontab -e

Start Cron Service:

Starts the Cron service:

    $ /etc/init.d/crond start

Stop Cron Service:

Stops the Cron service:

    $ /etc/init.d/crond stop

View Crontab:

Shows all Crontab tasks:

    $ crontab -l

2. Directories

Change File Directory

Changes between two different file directories. To change from the current_directory to the target_directory, you’d input the following command:

    $ cd/target_directory/current_directory

If you type ‘cd’ and press ‘Enter’, it’ll go back to the home directory.

Current Directory:

Shows the current directory you are in:

    $ pwd

List Directory

Shows all files in the current directory:

    $ ls /current_directory

Make Directory

Makes a new, empty directory:

    $ mkdir test_directory

Remove Directory

Removes an empty directory:

    $ rmdir test_directory

3. Files

Copy File:

Copies a file by taking two arguments. The first is the file you want to copy and the second is where to copy it to:

  • Go to the directory where the target file is located:
      • $ ls /home/target_directory
  • Input the name of the target file and the new directory:
      • $ cp target_file.txt /home/new_directory

Locate File:

Locates a file in a system. Use the ‘i’ argument to ignore the case and ‘*’ to separate words:

    $ locate -i *target*this

Make File:

Makes a new, empty file. If you wanted to make a Javascript file, you’d add the ‘.js’ extension:

    $ touch test_file.js

Move File:

Move a file between directories by taking two arguments. The first is the file you want to move and the second is where to move it to:

  • Go to the directory where the target file is located:
    • $ ls /home/target_directory
  • Input the name of the target file and the new directory:
    • $ mv target_file.txt /home/new_directory

The ‘mv’ command can also be used to rename a file:

    $ mv target_file.txt targetTwo_file.txt

Remove File:

Removes files and directories with files in it:

    $ rm test_file.js

4. Miscellaneous

Learn More About A Command:

Shows the manual pages of a command and more information on how to use it. If you wanted to know more about the ‘cd’ command, input:

    $ man cd

or

    $ cd -help

Restart Command:

Shuts down the system from a terminal session:

    $ /sbin/shutdown -r now

5. System

Login as root:

    $ sudo -s

Select Editor:

Shows list of editors to choose from:

    $ select-editor

Set Root Password:

Sets a root password if it’s not already set:

    $ sudo passwd
  • Type in the password for the logged in user and press ‘Enter’.
  • Type in desired root password and press ‘Enter’.
  • Retype the root password and press ‘Enter’.
  • The root password should be set. Login using root password.

Set Timezone:

Sets the desired timezone:

    $ sudo dpkg-reconfigure tzdata

References: