"top" command can not support chinese characters in ubuntu 12.04 - character

I found a problem, can anyone help to solve?
My Ubuntu "top" command cannot display Chinese characters correctly. It's using unrecognized characters, see the below:
joe#joe-us:~/app$ top -bc -n 1|grep home
1989 joe 20 0 34760 2564 2148 S 0 0.1 0:00.00 /usr/lib/gvfs//gvfs-fuse-daemon -f /home/joe/.gvfs
9577 joe 20 0 217m 40m 19m S 0 1.0 3:01.42 /home/joe/��?�?�/�?� sublime_text �??�?��?�
13885 joe 20 0 5828 820 732 S 0 0.0 0:00.00 grep --color=auto home
joe#joe-us:~/app$
For the same process, command "ps" works OK.
joe#joe-us:~/app$ ps -ef|grep home
joe 1989 1 0 10:11 ? 00:00:00 /usr/lib/gvfs//gvfs-fuse-daemon -f /home/joe/.gvfs
joe 9577 1 1 12:00 ? 00:03:01 /home/joe/桌面/到 sublime_text 的链接
joe 13883 12362 0 16:36 pts/0 00:00:00 grep --color=auto home
My system can support Chinese characters well now, here is the environment
joe#joe-us:~/app$ echo $LANGUAGE
zh_CN:zh
joe#joe-us:~/app$
joe#joe-us:~/桌面$ ls
aliedit.sh github github~ keeper.php Logo root root~ 到 sublime_text 的链接
joe#joe-us:~/桌面$
joe#joe-us:~$ echo $TERM
xterm
right display:/home/joe/桌面/到 sublime_text 的链接
wrong display:/home/joe/��?�?�/�?� sublime_text �??�?��?�
Thank you very much!

Related

how to find string boot on the /etc/fstab file and replace UUID with kernel device name /dev/sda1?

how to find string boot on the /etc/fstab file and replace UUID with kernel device name /dev/sda1?
cat /etc/fstab
/dev/mapper/vg00-root / xfs defaults 0 0
UUID=6fc6605f-796e-4e0b-a8f7-8b339c46b1a9 /boot xfs defaults 0 0
/dev/mapper/vg00-tmp /tmp xfs defaults 0 0
/dev/mapper/vg00-var /var xfs defaults 0 0
/dev/mapper/vg00-crash /var/crash xfs defaults 0 0
/dev/mapper/vg00-log /var/log xfs defaults 0 0
/dev/mapper/vg00-swap swap swap defaults 0 0
sed 's/UUID/\/dev\/sda1/g' /etc/fstab
I'm making the assumption that you want to replace UUID=6fc6605f-796e-4e0b-a8f7-8b339c46b1a9 for /dev/sda1/, which is in general a bad idea. The UUID is a unique id belonging to the disk. If you want to replace the disk, I suggest to try to get the UUID with blkid.
Otherwise, you should extend the regex in order to replace that part:
$ sed 's/UUID=6fc[^ ]*/\/dev\/sda1/g' fstab
Note that U've added 6fc to make sure you will not change every UUID= line.
List files under /dev/disk/by-uuid:
ls -l /dev/disk/by-uuid/
...to obtain something like this:
lrwxrwxrwx 1 root root 10 ott 4 18:37 53bc3708-e45d-4352-977a-a62c6a4fd5c8 -> ../../dm-1
lrwxrwxrwx 1 root root 10 ott 4 18:37 6a23dfcf-e36d-45c8-a468-d3976b5239f3 -> ../../dm-0
lrwxrwxrwx 1 root root 10 ott 4 18:37 7d6e75e9-7ed2-4412-8acd-2de50ffa0034 -> ../../sda1
As you see, you find the old style device name in the right of the output, as link target.
In the uplevel directory, you can find disks categorized by id and by path, not only by uuid. Beautiful!

Debugging a specified emacs of multiple, when one is frozen

Two emacs server are running on my machine
$ ps -ef |grep emacs | sed "s/$USER/me/g"
me 4010 1 6 13:52 ? 00:02:58 /snap/emacs/25/usr/bin/emacs --daemon=orging
me 4538 1 3 13:52 ? 00:01:45 /snap/emacs/25/usr/bin/emacs --daemon=coding
me 4622 1 0 13:52 pts/1 00:00:00 /snap/emacs/25/usr/bin/emacsclient /home/me/ORG/os.org -c -s orging
me 4623 1 0 13:52 pts/1 00:00:00 /snap/emacs/25/usr/bin/emacsclient /home/me/ORG/algorithms.org -c -s coding
me 8945 3548 0 14:38 pts/1 00:00:00 grep --color=auto emacs
The one of 'orging` is frozen,
Upon reading debugging - What do I do when Emacs is frozen? - Emacs Stack Exchange, I got the solution
pkill -SIGUSR2 emacs
How could apply the operation to the specified emacs saying 'orging'?
Use the kill command and specify the pid of the emacs instance you want, in this case 4010:
kill -SIGUSR2 4010

Alias directory minus one file

I'd like to make an alias for a directory that contains many files. If I open the aliased directory, I want to view all files except for one. New files will be added to the directory over time, and I want everything to be aliased except for the one file permanently not-aliased.
Is it possible to set this up without needing to run a script every time a file in the directory changes?
E.g.: myDir contains fileA, fileB, and fileC.
I want myAliasedDir to contain fileA and fileB, but not fileC.
Can you get away with symbolic links?
Assuming your shell is bash:
$ shopt -s extglob
$ mkdir dir1 dir2
$ cd dir1
$ touch file{1..3}
$ ls -l
total 0
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file1
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file2
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file3
$ cd ../dir2
$ for f in ../dir1/!(file2); do ln -s "$f"; done
$ ls -l
total 8
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file1 -> ../dir1/file1
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file3 -> ../dir1/file3

Sed remove all content in line after \t

I have o/p like
19599 user 20 0 120m 32m 4260 S 14.0 5.3 3:21.13 app.out \t Wed Jun 8 09:31:06 UTC 2011
19599 user 20 0 120m 32m 4260 S 14.0 5.4 3:21.61 app.out \t Wed Jun 8 09:31:12 UTC 2011
19599 user 20 0 121m 32m 4260 S 12.0 5.4 3:22.31 app.out \t Wed Jun 8 09:31:17 UTC 2011
I want to remove all character starting from \t in the line.
How can I do that with sed?
I tried with awk -F t '{print $1}'
but it removing t from app.out .
I want o/p like
19599 user 20 0 120m 32m 4260 S 14.0 5.3 3:21.13 app.out
19599 user 20 0 120m 32m 4260 S 14.0 5.4 3:21.61 app.out
19599 user 20 0 121m 32m 4260 S 12.0 5.4 3:22.31 app.out
If I wrote the awk like this:
awk -F t '{print $1"t"}'
it works fine, but it is only a work around. How can I remove all character starting from \t in the line till end of line?
If the output contains the two characters backslash and 't', then you use:
sed 's/ *\\t.*//'
This removes the blanks leading up to the two characters, the backslash and the 't', plus everything after them.
If the output contains a tab character, then you need to replace the '\\t' with an actual tab character.
It sounds like you want the first field in a tab-delimited text. You might try one of:
cut -d $'\t' -f 1
awk -F '\t' '{print $1}'
sed $'s/\t.*//'
The $'' syntax is used in bash (and ksh and zsh I believe) to more easily allow for embedding escape sequences in strings.
awk 'BEGIN { FS = "\t" } 1 == 1 {print $1}' file.name
Just pipe it through:
sed 's/\(.*\)\t.*/\1/'

Convert `ls -lR` output to format of `find` output

I need to convert ls -lR output to the format of find output
E.g. I have a text file, which is an output of ls -lR. The file contains:
/tmp/1:
total 0
drwxr-xr-x 3 user1 ubuntu 80 May 10 21:13 2
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f1
/tmp/1/2:
total 0
drwxr-xr-x 2 user1 ubuntu 60 May 10 21:13 3
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f2
/tmp/1/2/3:
total 0
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f3
I want to convert this file to the second one with different format, just like find utility uses by default:
/tmp/1
/tmp/1/f1
/tmp/1/2
/tmp/1/2/f2
/tmp/1/2/3
/tmp/1/2/3/f3
If I have the fs, which was used for generating ls-lR, I'll just run a find /tmp/1, but in my case I have no access to the original fs.
Is it possible? There must be a short perl-script for this conversion.
You can use -ls as primary (which is slightly different from ls -l) or -exec ls -l {} +. It will however never be completely the same as ls -lR since that does different groupings and prints totals.
Actually, I think find . -type d -exec ls -l {} + is the closest approximation.