网上找了一堆资料,用来比较方便的rename
rename "s/oldstring/newstring//g" *
这个适合oldstring不是变量的情况,如果想用变量怎么弄,那就用shell了,直接在控制台输入
for((i=1;i<=9;i++))
do
mv oldname$i newname$i
done
这样比python,php之类的方便多了,给自己的小机灵赞一个~
网上找了一堆资料,用来比较方便的rename
rename "s/oldstring/newstring//g" *
这个适合oldstring不是变量的情况,如果想用变量怎么弄,那就用shell了,直接在控制台输入
for((i=1;i<=9;i++))
do
mv oldname$i newname$i
done
这样比python,php之类的方便多了,给自己的小机灵赞一个~
linux移动文件夹中前10个文件
linux复制文件夹中前10个文件
ls |head -n 10 |xargs -i cp -r {} /target
linux移动文件夹中前10个文件
ls |head -n 10 |xargs -i mv {} /target
xampp采用的是proftpd服务端,这个不像我们Win环境下常用的Serv-U,用户帐户不是在服务端工具里面进行配置,而是在linux系统帐户里面配置的。因此我们可以使用命令:
groupadd ftpusers
先在系统中创建一个名称为ftpusers的用户组,这里的名称可以随便设置,主要是为了区分ftp帐户与系统其他类型的帐户所以我这里就命名为ftpusers,然后在这个组里面添加一个用户:
useradd -d /opt/lampp/www/site1 -g ftpusers -s /sbin/nologin site1ftp
第一个参数-d表示用户home目录,其中/opt/lampp/www/这个路径必须是存在的,而site1则是在该命令执行时自动创建的。第二 个参数-g表示此用户隶属于哪个用户组,第三个参数-s表示此用户的shell环境,为安全起见我们应该设置为一个无权限的路径。最后一个参数才是此帐户 的登录名称,我这里是site1ftp。
创建好之后我们就要为该帐户设置一个密码了:
passwd site1ftp
执行该命令后按提示输入两次密码即可完成帐户site1ftp的密码设置了。
接下来我们设置一下帐户home目录的权限:
chmod -R 777 /opt/lampp/www/site1
至此,ftp帐户的添加算是完成了,顺便提示一下,删除帐户的命令是userdel,修改帐户的命令是usermod,存储帐户的文件路径为/etc/passwd。
另外,为安全起见,我们应该在proftpd的服务配置文件(一般路径是/opt/lampp/etc/proftpd.conf)中修改一下 DefaultRoot为ftpusers,将ftpusers组里面的用户访问范围限制在其home目录。也可以把DefaultRoot设为~(键盘 左上角的那个符号),这样表示所有的组里面的用户都有这个限制了。如果要单独设置两个组或更多的组你必须另起一行或多行,说明如下:
DefaultRoot ftpusers #限制ftpusers组里面的用户
DefaultRoot ~ #限制所有组里面的用户
DefaultRoot ftpusers DefaultRoot nobody #限制ftpusers组及nobody组里面的用户
DefaultRoot ftpusers,nobody #限制既隶属于ftpusers组同时也隶属于nobody组里面的用户
对了,还差一个步骤,应该在proftpd配置文件中对ftp目录添加可重写的权限,如下:
<Directory /opt/lampp/www/*> AllowOverwrite on </Directory>
否则会出现ftp上传文件时无法覆盖同名文件的问题
ln -s /opt/lampp/bin/mysql /usr/bin
修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/opt/lampp/bin
export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功
系统
# uname -a # 查看内核/操作系统/CPU信息
# head -n 1 /etc/issue # 查看操作系统版本
# cat /proc/cpuinfo # 查看CPU信息
# hostname # 查看计算机名
# lspci -tv # 列出所有PCI设备
# lsusb -tv # 列出所有USB设备
# lsmod # 列出加载的内核模块
# env # 查看环境变量
资源
# free -m # 查看内存使用量和交换区使用量
# df -h # 查看各分区使用情况
# du -sh <目录名> # 查看指定目录的大小
# grep MemTotal /proc/meminfo # 查看内存总量
# grep MemFree /proc/meminfo # 查看空闲内存量
# uptime # 查看系统运行时间、用户数、负载
# cat /proc/loadavg # 查看系统负载
磁盘和分区
# mount | column -t # 查看挂接的分区状态
# fdisk -l # 查看所有分区
# swapon -s # 查看所有交换分区
# hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)
# dmesg | grep IDE # 查看启动时IDE设备检测状况
网络
# ifconfig # 查看所有网络接口的属性
# iptables -L # 查看防火墙设置
# route -n # 查看路由表
# netstat -lntp # 查看所有监听端口
# netstat -antp # 查看所有已经建立的连接
# netstat -s # 查看网络统计信息
进程
# ps -ef # 查看所有进程
# top # 实时显示进程状态
用户
# w # 查看活动用户
# id <用户名> # 查看指定用户信息
# last # 查看用户登录日志
# cut -d: -f1 /etc/passwd # 查看系统所有用户
# cut -d: -f1 /etc/group # 查看系统所有组
# crontab -l # 查看当前用户的计划任务
服务
# chkconfig –list # 列出所有系统服务
# chkconfig –list | grep on # 列出所有启动的系统服务
程序
# rpm -qa # 查看所有安装的软件包
用find命令查找最近修改过的文件
该文章转载自网络大本营:[url]http://www.xrss.cn/Dev/LINUX/200751213231.Html[/url]
linux的终端上,没有windows的搜索那样好用的图形界面工具,但find命令确是很强大的。
比如按名字查找一个文件,可以用 find / -name targetfilename 。 唉,如果只知道名字,不知道地点,这样也不失为一个野蛮有效的方法。
按时间查找也有参数 -atime 访问时间 -ctime 改变状态的时间 -mtime修改的时间。但要注意,这里的时间是以24小时为单位的。查看man手册后使用,你会很迷惑: -mtime n: File
find ./ -mtime 0:返回最近24小时内修改过的文件。
find ./ -mtime 1 : 返回的是前48~24小时修改过的文件。而不是48小时以内修改过的文件。
返回10天内修改过的文件?find还可以支持表达式关系运算,所以可以把最近几天的数据一天天的加起来:
find ./ -mtime 0 -o -mtime 1 -o -mtime 2 ……虽然比较土,但也算是个方法了。
还有没有更好的方法,我也想知道。。。
另外, -mmin参数-cmin / – amin也是类似的。
解决Axure RP输出成html放到网站后,不能读取中文网址页面的办法
Axure RP输出 html档案,如果左侧Page列表是用中文命名,在自己的计算机上可以正常点选连结,但是放到网站上会发生无法读取的情况: 点左侧选单,但右侧无法出现对应的数据。
这个状况的问题出在 「放」到网络上的方法以及网站操作系统是否支持中文文件名?
以网站操作系统来区分,把Axure RP输出的html prototype传到网站上的方法:
1. Web放在Windows OS(已经支持中文文件名)
以网络芳邻的方式 (在局域网络里头),直接把Axure RP输出的html档案,复制或搬移到web server可读取的目录之下,中文文件名的网址不会有问题。
2. Web放在Linux之类的OS (必须支持中文档名)
CentOS 终端命令行中文乱码的解决
安装CentOS的时候选择了中文,结果在终端不能显示中文,都是乱码,解决方法:
修改/etc/sysconfig/i18n,内容为(ubuntu:/usr/share/i18n/SUPPORTED)
LANG=”zh_CN.GB18030″
LANGUAGE=”zh_CN.GB18030:zh_CN.GB2312:zh_CN”
SUPPORTED=”zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en”
SYSFONT=”lat0-sun16″
安装中文字体:
#yum install fonts-chinese.noarch
退出重新登录即可
然后采用 FTP上传Axure RP输出的html文件,必须将 FTP传输模式改成 『UTF8″,否则当FTP软件以ANSI或其它编码传输到 Linux的档案目录上,Apache是无法辨认出这种编码的中文文件名的。我们建议采用FileZilla,FileZilla支持传输编码的设定。
如果没有FTP,也可以使用sftp的方式上传,推荐一个工具 sftpDrive,可以将文件夹直接拷贝到Linux服务器上。
举例:
下面这个prototype使用了中文html,仍然可以顺利浏览。
http://userxper.com/samples/zh/Prototypes/demo_travelsite/index.html
SMB服务不存在这个问题,也是一个不错的替代方案
gunzip *.tgz( 可将.tgz 转为.tar 文件)
范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar
[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩!
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==打包后,以 gzip 压缩
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==打包后,以 bzip2 压缩
范例二:查阅上述 /tmp/etc.tar.gz 文件内有哪些文件?
[root@linux ~]# tar -ztvf /tmp/etc.tar.gz
范例三:将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下
[root@linux ~]# cd /usr/local/src
[root@linux src]# tar -zxvf /tmp/etc.tar.gz
范例四:在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
范例五:将 /etc/ 内的所有文件备份下来,并且保存其权限!
[root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc
范例六:在 /home 当中,比 2005/06/01 新的文件才备份
[root@linux ~]# tar -N ‘2005/06/01′ -zcvf home.tar.gz /home
范例七:我要备份 /home, /etc ,但不要 /home/dmtsai
[root@linux ~]# tar –exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
范例八:将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件!
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -cvf – /etc | tar -xvf –
.tar
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
———————————————
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz 和 .tgz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
———————————————
.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2 或tar –bzip xvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
———————————————
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
———————————————
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
———————————————
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
压缩一个目录使用 -r 参数,-r 递归。例: $ zip -r FileName.zip DirName
———————————————
.rar
解压:rar x FileName.rar
压缩:rar a FileName.rar DirName
rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
Ubuntu Linux系统包含两类环境变量:系统环境变量和用户环境变量。系统环境变量对所有系统用户都有效,用户环境变量仅仅对当前的用户有效。
用户环境变量通常被存储在下面的文件中:
上述文件在Ubuntu 10.0以前版本不推荐使用。
系统环境变量一般保存在下面的文件中:
/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。
如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):
1
|
sudo nano /etc/profile |
在里面加入:
1
2
3
4
5
6
|
JAVA_HOME= /usr/jdk1 .6.0_25 export JAVA_HOME PATH=$PATH:$JAVA_HOME /bin export PATH CLASSPATH=.:$JAVA_HOME /lib export CLASSPATH |
你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:
1
|
$ source /etc/profile |
需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。
其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。
更详细的说明可以参考这里。
当然如果想使用文本编辑工具修改环境变量,可以使用root权限登录后,直接用文本编辑器打开修改保存
也可以普通用户权限下把文件复制到桌面等修改后用root权限覆盖回去
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). if [ -d /etc/profile .d ]; then for i in /etc/profile .d/*.sh; do if [ -r $i ]; then . $i fi done JAVA_HOME= /usr/hadoop/jdk1 .6.0_25 export JAVA_HOME PATH=$PATH:$JAVA_HOME /bin export PATH CLASSPATH=.:$JAVA_HOME /lib export CLASSPATH unset i fi if [ "$PS1" ]; then if [ "$BASH" ]; then # The file bash.bashrc already sets the default PS1. # PS1='\h:\w\$ ' if [ -f /etc/bash .bashrc ]; then . /etc/bash .bashrc fi else if [ "`id -u`" - eq 0 ]; then PS1= '# ' else PS1= '$ ' fi fi fi |
If you are a developer you need C and C++ Compiler for your development work.In ubuntu you can install the build-essential for C and C++ compilers.
Install C and C++ Compilers in Ubuntu:
[code]sudo aptitude install build-essential[/code]
This will install all the required packages for C and C++ compilers
Testing C and C++ Programs
Compiling Your first C Programs
Now you need to open first.c file
sudo gedit first.c
add the following lines save and exit the file
[code]
#include<stdio.h>
int main(){
printf("hello,world\n");
return 0;
}
[/code]
Firstly compile the code using the following command
cc -c first.c
that would produce an object file you may need to add to the library.
then create an executable using the following command
cc -o first first.c
Now run this executable using the following command
./first
Output should show as follows
Hello, world
Compiling your first C++ program
If you want to run c++ program follow this procedure
g++ is the compiler that you must use.
you should use a .cpp file extension rather than a .c one
You need to create a file
sudo gedit first.cpp
add the following lines save and exit the file
[code]
#include<iostream>
int main(){
std::cout<<"Hello World!" <<std::endl;
return 0;
}
[/code]
Run your C++ Program using the following command
g++ first.cpp -o test
./test
Output should show as follows
Hello World!
CP命令 格式: CP [选项] 源文件或目录 目的文件或目录 选项说明:-b 同名,备分原来的文件 -f 强制覆盖同名文件
-r 按递归方式保留原目录结构复制文件!!!!!!