Common ssh file/folder commands for the web developer

Sometimes web developers don’t need to just build websites but we need to go and poke, tweak and otherwise tinker with the server themselves.  To a windows-based developer getting down and dirty with the Linux command line can be a little daunting.  However, there are some standard commands that you will need which may help ease you in.  Often with commands you will be able to apply additional instructions or parameters called arguments.  These may preceded with – or  –. You can often concatenate these (see ls below for an example).  There are usually a lot of arguments you can use and they are different for each command.  You can get help (a list of the things you can do) by adding -h  or -help after the command.  e.g.

ls -help

Listing or showing files

List files in current directory:

ls

Hey where is my .htaccess file?
List ALL files:

ls -a

List files with additional info (permissions, etc)

ls -l

List all files with additional info

ls -al

Changing or navigating directories

cd [directoryname]         (where [directoryname] is the folder, e.g.   cd  www

Go back a directory:

cd ../

Go back two directorys:

cd ../../

Navigate to the base directory:

cd /

There are usually two key locations that a web developer needs to know about:  where the configuration and log files are and where the web files are.   The configuration files are (usually) located inside the etc folder.  You would navigate to this by doing:

cd /etc

You are probably interested in the apache (web server) stuff so look for a folder called httpd.  Note the ‘d’ at the end historically stands for daemon – basically refers to a service or something that runs in the background.

Log files such as error logs or visitor logs are probably located in the /var/log  directory

cd /var/log

The web folder might be different depending on which version of linux you are running but a common one would be

cd /var/www/html/

This latter one means go to the root /   and then into var, then into www, then into html

Remove files and folders

be very careful with your location when using rm (remove).  Do not delete system files or folders.  There be dragons and you could have a CDM (career defining moment).

rm myUnwantedFile.html

Remove all gif files from current folder

rm *.gif

Delete an empty folder

rmdir  myFolder

Delete a folder and contents

rm -rf myUnwantedFolder

the -r means recursive and the -f will stop it asking you to confirm whether you want to delete

Moving Files

Move myfile.html to newfile.html

mv myfile.html newfile.html

Move a directory and contents

mv images/* media/images

Copying Files

Copy originalFile.html  to a new file, copiedFile.html

cp originaFile.html copiedFile.html

Copy a folder/directory and all files within

cp -R images/  images_backup/

the -R means recursively

If you want to overwrite any existing files during the copy process you will need to use the -f argument:

cp -Rf image/  images_backup/

Handy Tips

When using an ssh command line console you can cycle through previously typed commands using the up and down arrow keys.

If you have long file or folder names, to save typing them start typing the beginning and then press the tab key to auto-complete the file or folder name.  If you have similar name files pressing tab will fill the gap until you need to decide which bit you want.  Just type again and then press tab again after that.  Give it a go to see what I mean.石崎電機製作所 GK2030Y [電撃殺虫器 (屋内用)]
★ポイント最大7倍★【全国配送可】-らくらくあるくん(R)(ネスティング歩行器) グリーン ナビス 型番Rkun-RGR  JAN4580110270563 asn8-6501-03 -【医療?看護用
ミスト・羽毛肌布団 (シングル)
【TMHG95EC1】TOTO シャワーバー(水栓なしタイプ) 【トートー/TOTO】
★ポイント5倍★フランスベッド羊毛入りデュラテクノマットレスダブル【代引不可】[CK] [L] [00]
【送料無料&全品P5倍】 【1ケース納品】 ジェックス パックDE赤虫 10g×2 ×120個入 ★税抜5000円以上で送料無料★激安祭
(業務用10セット) スリーエム 3M ダスタークロスレギュラーM D/C REG M 【×10セット】
【工事費込セット(商品+基本工事)】[MSZ-JXV2217-W] 三菱 ルームエアコン JXVシリーズ 霧ヶ峰 ハイスペックモデル 冷暖房:6畳程度 / 六畳 2017年モデル 単相100V?15A
【運賃見積り】【直送品】サカエ SAKAE 中量棚BW型アイボリー BW-9763
K2 スノーボード【SNOW3点SET】《キッズモデル》《 GIRLS GROM PACKAGE 》ボード/ビンディング/ブーツ3点セット キッズ ユース ジュニア 子供用

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *