OS X控制台命令

OS X系统其实是基于Unix的系统,因此控制台命令基本可以通用。

 ls -l 查看目录下的具体文件信息 (去掉l就只看文件名)

pwd 查看当前所在的文件地址

进入某个新的文件或者地址

cd /

This will change the directory to /, the top of the whole UNIX directory structure. 


$ cd Documents

You’ll notice that I just passed it a directory named Documents, because I was in my home directory, that contains a directory called Documents. This is relative path, because I specified my destination relative to my current directory. I can provide an absolute path by providing the full path beginning with the /, or starting with my home directory (~) such as:

$ cd /Users/jim/Documents

When using cd, you can specify the new directory absolutely (beginning with a slash, like /var/www) or relative to your current location (without the initial slash).
or

$ cd ~/Documents

If you want to navigate “up”, that is to the directory that contains your current directory, you can use the special name ..which you can even use separated by slashes to navigate several levels up.

From my Documents directory, this command will take me up to my home directory.
$ cd ..

获取帮助

Fortunately, most commands have a manual. To read, use the man command. Pass the name of the command you want to learn about as it’s only argument. For instance to learn more about ls, run

$ man ls



更多的指令

Some more commands.

There are a ton of different commands you can use, but only a couple dozen will get you pretty effective in the command line.

We learned about ls, pwd, cd, and man.

Try using the man command to learn about these commands

  • mkdirMake a new directory

  • touchMake a new empty file

  • cpCopy a file

  • mvMove a file

  • rmRemove a file or directory (learn about the -r option)

  • less Show the contents of a file in a scrolling buffer


  • Getting your bearings: pwd, cd ls;

  • Viewing and moving files: cat, more, head, tail, mv, cp, rm;

  • Searching for files: find;

  • Looking through and editing files: grep, vi;

  • Backing up and restoring files and databases: tar, zip, unzip, mysqldump,mysql;

  • File permissions: chmod.


For instance, if you have an index.html file, run:

cat index.html

If your index.html file is more than a few lines long, it will rush past in a blur. You can use the more command to show it slowly, one page at time. After you type the command below, it will show you the first page. You can press the space bar to show the next page, “Enter” to show the next line, and Q to quit.

more index.html

You can also show just the first few or last few lines of a file with the head and tail commands. It shows 10 lines by default, but you can pass in any number:

head index.html
tail -20 index.html

If you would like to rename this file, use the mv command, short for “move”:

mv index.html indexold.html

Similarly, the cp is the copy command, and rm removes files.

cp index.html indexold.html
rm indexold.html



vi操作
vi is a complex editor. It can do most of the amazing things that a fully featured visual editor can do, but without the mouse. In brief, you can use the arrow keys to get around the file (or H, J, K and L on very basic terminals where even the arrow keys don’t work). To delete a character, press X. To delete a whole line, press DD. To insert a new character, press I. This takes you into “insert mode,” and you can start typing. Press the Escape key when finished to go back to “command mode.” Within command mode, type :w to save (i.e. write) the file and :q to quit, or :wq to do both at the same time.

MORE ADVANCED TIP: TAB COMPLETION

When changing directories and editing files, you might get tired of having to type the file names in full over and over again. The Terminal loses some of its shine this way. This can be avoided with command-line completion, performed using tabs.

It works like this: start typing the name of a file or a command, and then press Tab. If there is only one possibility, Linux will fill in as much as it can. If nothing happens, it means there is more than one possibility. Press Tab again to show all of the possibilities.



修改权限:

chmod command, which changes file permissions. The three sets of permissions are represented in commands with u(“user” or owner), g (“group”), o (“other” or everyone else) or a (“all”). So, to enable all users to read bg.jpg, either of these would work:

chmod go+r images/bg.jpg
chmod a+r images/bg.jpg

If this file were also part of a CMS, then you’d have to also add write permissions before the CMS could overwrite it:

chmod a+rw images/bg.jpg

You can also make these changes to all files in all of the subdirectories by adding -R. This recursive operation is not supported by some FTP programs and so is a useful command-line tool:

chmod -R a+rw images/

Directories also need the x (“execute” permission), but files generally don’t (unless they are in a cgi-bin). So, you can give everything rwx (read, write and execute) permissions and then take away the x from the files:

chmod -R a+rwx images/chmod -R a-x `find images/ -type f`

However, this does leave everything rather open, making it easier for hackers to gain a foothold. Ideally, your set of permissions should be as restrictive as possible. Files should be writable by the Apache user only when needed by the CMS.


MORE ADVANCED TIP: CHOWN AND THE SUPERUSER

Another useful permissions command is chown. It changes the owner of a file. However, you have to be logged in as a user with sufficient privileges (such as root) in order to run it. To make www-data the owner of bg.jpg, run this:

chown www-data images/bg.jpg

This will probably return “Permission denied.” You have to run the command as the superuser. For this, you will need to find the root password for your server, and then run the following:

sudo chown www-data images/bg.jpg

You will definitely need to be the superuser if you want to edit configuration files, such as Apache’s:

sudo vi /etc/httpd/conf/httpd.conf

If you want to become the superuser for every command, run this:

su

This is dangerous, though, because you could easily accidentally remove things — especially if you are using the rm command, and particularly if you’re using it in recursive mode (rm -r), and most especially if you also force the changes and ignore any warnings (rm -r -f).


转载于:https://my.oschina.net/Bruce370/blog/424149

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值