Skip to content

Navigate Linux by the Command Line

Sometimes, just sometimes when you use Linux as a home user you need to navigate Linux by the command line. As the Linux novice you are, you need a quick intro to Linux shell commands if you want to find files and edit documents in that scary black hole that looks like it is going to suck you in when it opens up on your screen.

Lucky you, you have me. Here is a brief guide to the basic commands needed to get around Linux with text commands. Shell commands are easy to use and easy to remember but bookmark this page in case you get hit on the head later today and come down with a shocking case of amnesia.

Enjoy this quick guide to Linux command line navigation. Remember to share with friends and comment below.

This cheat sheet works for desktop Linux and web server Linux.

List files

Files are listed with the ls command.

File names that start with a dot are hidden. Type ls -a to view all files and directories including hidden files. Use ls to see only files and directories that are not hidden.

Hidden files are hidden to protect them from you. Treat hidden files with respect when you edit them.

  • First command is ls
  • Second command is ls -a

Change directory

Directory changes are made with the cd command. Type cd followed by the directory you wish to go to. If you typed cd /home/your-name you would be taken to your home directory.

A shorthand way to access your home directory is cd ~

The tilde, ~, represents the home directory of the active terminal user e.g. you. If you type cd ~ into a terminal you would be taken to the directory /home/your-name/.

To move up one directory, type cd ..

To go to the root directory type cd /

  • Third command is cd
  • Fourth command is cd ~
  • Fifth command is cd ..
  • Sixth command is cd /

Edit files

Files are edited with a command-line text editor. I like Nano. Other Linux admins use Vim. I think Vim is too complicated.

Type nano to start the Nano text editor.

You can tell Nano to open a file by either

  • Browsing to the file location then typing ‘nano file-name’, or
  • Telling nano the path to the file along with the file name

Opening nano with nano /home/downloads/example.txt would open example.txt stored in /home/downloads

Browsing to the downloads directory by first typing cd ~/downloads then typing nano example.txt would also open example.txt.

Some files can only be edited when opened by a user with admin rights. Type sudo nano file-name to edit protected files.

Nano has a menu that shows at the bottom of the screen. Commands in the menu are run by pressing Ctrl plus the specified key for the menu item. For example, Ctrl+X closes Nano.

Nano offers to save file edits on exit.

  • Seventh command is nano
  • Eighth command is sudo nano
  • Ninth command is nano /directory/file-name

Names with Spaces

Some directories and file names contain spaces. The easiest way to handle these directory names is to wrap them in single quotes.

  • If we need to edit a file name My Notepad we would open it with nano ‘My Notepad’.
  • If we need to enter a directory named My Documents we would enter it with cd ‘My Documents’.

Locate a file or directory

Use the locate command to locate files with loose name matching. Type locate file-name to find files with names that contain file-name.

Use find to find files with exact name matching. Type find -name file-name to find the file file-name. Type find PATH -name file-name to find files within or under the specified path.

For example,

  1. find / -name example.txt will list paths to files called example.txt stored in and below the root directory.
  2. find ~ -name example.txt will list paths to files called example.txt stored in and below your home directory.
  3. find -name example.txt will list paths to files called example.txt stored in and below the currently browsed directory.
  4. locate example will find files with names that contain the text ‘example’. The files could be anywhere on the computer.
  5. locate example.txt will find files with names that contain the text ‘example.txt’. The files could be anywhere on the computer.

Want to edit the files found with locate? Use backticks. Nano will open all files found:

  • nano `locate file-name`

Backticks look like single slanted quotes. The backtick key is normally found to the left of the number 1 on your keyboard.

If the list of locations is too long to display on one page, you聽 can pipe the results through the less command. This will spread the list of found files over several pages. The pipe is the vertical line character on your keyboard that looks like |. For example ls | less or locate text | less.

  • Tenth command is locate
  • Eleventh command is less

Locate a command program

Need to know where the launch script for kate is located or where the man page for Gimp cna be found? Use whereis. ‘whereis’ locates the binary, source, and manual page files for a command.

Type whereis kate to see where the kate binary program is (a binary file is called an executable file in Windows).

  • Twelfth command is whereis

Getting Help

Linux comes with a manual pre installed free of charge. There is a manual help page for most commands. Whenever stuck type man followed by the command name.

Type man man to see the help file for the manual.

Type man cd to see the manual for the cd command.

Pay attention to this: press Q or Ctrl+Q to quit the man page. Use arrow keys, page up and page down to navigate manual pages.

  • Thirteenth command is man

Miscellaneous commands

These next few commands are important. This commands make it possible to run a command line application like top, to stop the app then run another app like man.

  • See who you are logged in as with whoami
  • Stop a running program like top with Ctrl+C
  • Quit a running program like nano with Ctrl+Q
  • Shut the system with sudo shutdown -P now
  • Restart the system with sudo shutdown -r now
  • Or reboot the system with sudo reboot
  • View running processes with top
  • See Linux super moo powers with apt-get moo
  • View your terminal history with history
  • Clear the screen with clear

Sharing is caring!

Categories Beginner's Info
Support our work. Donate a few dollars to JournalXtra.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment. x
()
x
| Reply

PHP网站源码罗湖网站优化排名坂田网站关键词优化南山网站设计模板坪山百搜标王大鹏网站优化排名大浪网络广告推广坂田SEO按天计费坪地网站搜索优化盐田网站定制坪山企业网站制作西乡网站优化按天扣费深圳网站排名优化松岗百度竞价包年推广沙井网站建设设计大运至尊标王东莞营销型网站建设永湖营销网站观澜网站优化按天扣费惠州高端网站设计宝安模板网站建设横岗网站设计福永如何制作网站沙井网页制作光明seo网站推广布吉seo排名大芬百姓网标王松岗网站搜索优化罗湖百搜词包龙岗百度竞价包年推广盐田seo网站推广歼20紧急升空逼退外机英媒称团队夜以继日筹划王妃复出草木蔓发 春山在望成都发生巨响 当地回应60岁老人炒菠菜未焯水致肾病恶化男子涉嫌走私被判11年却一天牢没坐劳斯莱斯右转逼停直行车网传落水者说“没让你救”系谣言广东通报13岁男孩性侵女童不予立案贵州小伙回应在美国卖三蹦子火了淀粉肠小王子日销售额涨超10倍有个姐真把千机伞做出来了近3万元金手镯仅含足金十克呼北高速交通事故已致14人死亡杨洋拄拐现身医院国产伟哥去年销售近13亿男子给前妻转账 现任妻子起诉要回新基金只募集到26元还是员工自购男孩疑遭霸凌 家长讨说法被踢出群充个话费竟沦为间接洗钱工具新的一天从800个哈欠开始单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#中国投资客涌入日本东京买房两大学生合买彩票中奖一人不认账新加坡主帅:唯一目标击败中国队月嫂回应掌掴婴儿是在赶虫子19岁小伙救下5人后溺亡 多方发声清明节放假3天调休1天张家界的山上“长”满了韩国人?开封王婆为何火了主播靠辱骂母亲走红被批捕封号代拍被何赛飞拿着魔杖追着打阿根廷将发行1万与2万面值的纸币库克现身上海为江西彩礼“减负”的“试婚人”因自嘲式简历走红的教授更新简介殡仪馆花卉高于市场价3倍还重复用网友称在豆瓣酱里吃出老鼠头315晚会后胖东来又人满为患了网友建议重庆地铁不准乘客携带菜筐特朗普谈“凯特王妃P图照”罗斯否认插足凯特王妃婚姻青海通报栏杆断裂小学生跌落住进ICU恒大被罚41.75亿到底怎么缴湖南一县政协主席疑涉刑案被控制茶百道就改标签日期致歉王树国3次鞠躬告别西交大师生张立群任西安交通大学校长杨倩无缘巴黎奥运

PHP网站源码 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化