Basic Unix commands

Some basic unix commands:

  • ls -o : List files and directories in the current directory.
    ls -ao : List files and directories in the current directory, including hidden ones.
  • cd [dir-path] : Change to, or change current directory to the directory indicated by [dir-path].
    cd ~ : Change to your home directory, which in most cases would be /home/yourusername.
    cd .. : Change to the parent directory of the current one.
    cd – : Change to the last directory you are in.
  • pwd : Show the full path to the current directory.
  • mkdir [dir-path] : Create an empty directory in the specified directory indicated by [dir-path].
  • rmdir [dir-path] : Delete an empty directory in the specified directory indicated by [dir-path].
  • rm [file-path] : Delete a file indicated by [file-path].
    rm -f [file-path] : Forcibly delete a file indicated by [file-path], that is, without having to confirm before deletion.
    rm -r [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it.
    rm -rf [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it, without having to confirm before deletion.
  • mv [file-path]/[dir-path] [dir-path] : Move a file or directory indicated by [file-path] or [dir-path] to the directory indicated by the latter [dir-path].
    mv [file-path] [file-path] : Rename the file indicated by the first [file-path] to another indicated by [file-path]. Or. Move the first file to a different location and rename it as specified in the second [file-path].
  • cp [file-path] [dir-path] : Copy the file indicated by [file-path] to the directory indicated by [dir-path].
    cp [file-path] [file-path] : Duplicate the same file indicated by [file-path] with another name indicated by the second [file-path]. Or. Copy the first file to another location and rename it as specified in the second [file-path].
    cp -r [dir-path] [dir-path] : Copy a whole directory including everything underneath it indicated by the first [dir-path] to another directory indicated by the second [dir-path].
  • tar -zxf [file-path] : Extract all things in an archive extensioned with .tar.gz indicated by [file-path] to the current directory.
    tar -xf [file-path] : Extract all things in an archive extensioned with .tar indicated by [file-path] to the current directory.
    tar -cf [file-path] ([file-path]/[dir-path], … ) : Create an archive indicated by the first [file-path] of the files indicated by [file-path]s or/and directories indicated by [dir-path]s.
  • gunzip [file-path] : Decompress a zipped file extensioned with .gz to the current directory.
    unzip [file-path] : Decompress a zipped file extensioned with .zip to the current directory.
  • chmod [xxx] [file-path]/[dir-path] : Change the privileges of a given file or directory indicated respectively by [file-path] and [dir-path] to xxx.
    chmod -r [xxx] [dir-path] : Change the privileges of a given directory indicated by [dir-path] to xxx.
  • more [file-path] : Display the content of the given file indicated by [file-path], one screen at a time.
  • ln -s [file-path] [file-path] : Create a symbol link for the first file, so that everything you do to the symbol link, a.k.a the second fake file, is reflected to the real file, except for when you delete the symbol link, the real file remains intact.
  • touch [file-path] : Create an empty file indicated by [file-path].
  • du -sh : Show disk usage of the current directory.
    du -sh * : Show disk usage of the current directory plus the statistics of all the files and directories underneath it.
  • grep [text] [file-path] : Search the file indicated by [file-path] with the text in [text].
  • mysqldump -h [hostname] -u [username] -p [password] [database] > [databasefile.sql] : Dump or backup the selected database on the selected host privileged by selected user identified by corresponding password to a SQL file.
    mysql -h [hostname] -u [username] -p [password] [database] < [databasefile.sql] : Restore the data in a SQL file to the selected database on the selected host privileged by selected user identified by corresponding password.
  • clear : Clear the screen so that you feel neat.
  • exit : Terminate the SSH dialogue and close the Putty window