ZHANG BIAO . ORG

^


linux screen 命令详解

• LIUNX • 阅读: 67382

linux screen 命令详解
一、背景

系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份、ftp 传输等等。通常情况下我们都是为每一个这样的任务开一个远程终端窗口,因为它们执行的时间太长了。必须等待它们执行完毕,在此期间不能关掉窗口或者断开连接,否则这个任务就会被杀掉,一切半途而废了。

二、简介

GNU Screen是一款由GNU计划开发的用于命令行终端切换的自由软件。用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换。

GNU Screen可以看作是窗口管理器的命令行界面版本。它提供了统一的管理多个会话的界面和相应的功能。

会话恢复
只要Screen本身没有终止,在其内部运行的会话都可以恢复。这一点对于远程登录的用户特别有用——即使网络连接中断,用户也不会失去对已经打开的命令行会话的控制。只要再次登录到主机上执行screen -r就可以恢复会话的运行。同样在暂时离开的时候,也可以执行分离命令detach,在保证里面的程序正常运行的情况下让Screen挂起(切换到后台)。这一点和图形界面下的VNC很相似。
多窗口
在Screen环境下,所有的会话都独立的运行,并拥有各自的编号、输入、输出和窗口缓存。用户可以通过快捷键在不同的窗口下切换,并可以自由的重定向各个窗口的输入和输出。Screen实现了基本的文本操作,如复制粘贴等;还提供了类似滚动条的功能,可以查看窗口状况的历史记录。窗口还可以被分区和命名,还可以监视后台窗口的活动。
会话共享
Screen可以让一个或多个用户从不同终端多次登录一个会话,并共享会话的所有特性(比如可以看到完全相同的输出)。它同时提供了窗口访问权限的机制,可以对窗口进行密码保护。
GNU's Screen 官方站点:http://www.gnu.org/software/screen/

三、语法

screen -AmRvx -ls -wipe-h <行数>-s

参数说明

-A  将所有的视窗都调整为目前终端机的大小。
-d <作业名称>  将指定的screen作业离线。
-h <行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r <作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s  指定建立新视窗时,所要执行的shell。
-S <作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或--list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

四、常用screen参数

screen -S yourname -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session

在每个screen session 下,所有命令都以 ctrl+a(C-a) 开始。
C-a ? -> 显示所有键绑定信息
C-a c -> 创建一个新的运行shell的窗口并切换到该窗口
C-a n -> Next,切换到下一个 window
C-a p -> Previous,切换到前一个 window
C-a 0..9 -> 切换到第 0..9 个 window
Ctrl+a [Space] -> 由视窗0循序切换到视窗9
C-a C-a -> 在两个最近使用的 window 间切换
C-a x -> 锁住当前的 window,需用用户密码解锁
C-a d -> detach,暂时离开当前session,将目前的 screen session (可能含有多个 windows) 丢到后台执行,并会回到还没进 screen 时的状态,此时在 screen session 里,每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。
C-a z -> 把当前session放到后台执行,用 shell 的 fg 命令则可回去。
C-a w -> 显示所有窗口列表
C-a t -> Time,显示当前时间,和系统的 load
C-a k -> kill window,强行关闭当前的 window
C-a [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、复制就像用使用 vi 一样

C-b Backward,PageUp 
C-f Forward,PageDown 
H(大写) High,将光标移至左上角 
L Low,将光标移至左下角 
0 移到行首 
$ 行末 
w forward one word,以字为单位往前移 
b backward one word,以字为单位往后移 
Space 第一次按为标记区起点,第二次按为终点 
Esc 结束 copy mode 

C-a ] -> Paste,把刚刚在 copy mode 选定的内容贴上

文章标签: liunx
点此生成 >> 文章海报


已经是第一篇文章了~
下一篇 : 2021年双十二,博客搭建完成
留言

取消回复



已有 28310 条留言
  1. nonebet_hvki
    2026-09-04 08:09:33
    回复

    Been using Nonebet for maybe five months now, mainly late nights, and figured I'd dump some thoughts since a few blokes here asked. Getting an account took no time — email and a password, that's it, though the ID verification hit me later, which every licensed site does anyway. Minimum was $20 which suits me.

    The lobby's big — I'd guess around 4,000 titles from memory. Pragmatic Play dominates, so Gates of Olympus, Big Bass, the usual suspects are sitting right on the front page. My go-to is Big Time Gaming Megaways because the volatility suits me. Microgaming back catalogue is there as well. Live dealer side runs on Evolution, which means real croupiers, roulette running 24/7 and Crazy Time which I watch more than I play.

    The welcome deal was a match up to around $750 with 200 spins, wagering was 35x which honestly is about average. They also had a small no deposit thing for a while but it comes and goes. Terms change fairly often so have a look at Nonebet Casino - Real-Money Gaming in 2026: A Practical Player Guide rather than trusting my numbers. What did get on my nerves is the $5 max bet cap during bonus play — I busted it by accident once and lost the lot. My fault, but still.

    Withdrawals have been decent. Bitcoin withdrawals landed same day both times, Skrill and Neteller were 24 hours or so, and the one card withdrawal took nearly four days which is the slow lane. Funding is instant with Visa, Mastercard or crypto.

    Their live chat answered me at 2am, actual humans once you get past the bot. No app for Nonebet that I've found — it's a browser thing, works well enough on the Android. It's a Curacao licence, which isn't the ACMA, obviously, make of that what you will if you're in Australia.

  2. 2026-09-04 08:09:54
    回复

    Probably going to mention this site in a write up I am working on later this month, and a stop at metricmint provided more material for that potential mention, content worth referencing in my own published work rather than just personal reading is content with the highest endorsement level and this site has earned that endorsement.

  3. 2026-09-04 09:09:01
    回复

    Thanks for the simple approach, too many sites bury the actual point under layers of unnecessary words, but here every line earns its place, and a look at rentgpuserver showed the same care for the reader which is something I will remember the next time I need answers on a topic.

  4. 2026-09-04 10:09:33
    回复

    Solid stuff, the kind of post that I will probably refer back to later this month when the topic comes up again, and a look at penpavilion only confirmed I should bookmark the site as a whole rather than just this single page for future reference and use across coming weeks.

  5. 2026-09-04 10:09:14
    回复

    Я понял: ещё немного — и я потеряю его навсегда. Мы пытались звонить в скорую, но они сказали: «Только если он сам захочет». Случайно наткнулся на сайт, где предлагали вывод из запоя на дому. выезд нарколога в Красноярске — это вернуло брата к жизни. Врач приехал, осмотрел его. Мы расплатились, и врач уехал. вызов нарколога для вывода из запоя https://vyvod-iz-zapoya-v-krasnoyarske-vka.ru Сохраните, поделитесь, не потеряйте для нашего города. Звоните, помогайте, спасайте. Вывод из запоя — это реальность, и она работает!

  6. 888starz_gfE
    2026-09-04 11:09:57
    回复

    Gram tu juz jakies pol roku, w zasadzie same automaty, wiec moge cos napisac. W 888starz katalog gier jest spory — grubo ponad 3000 automatow, z czego polowa to pewnie klony. Pragmatic Play jest wszedzie — klasyki typu Gates of Olympus sa oblegane, ale mam tez slabosc do Book of Dead. Znalazlem sporo Yggdrasil i BTG dla lubiacych mocniejsza wariancje.

    Live to Evolution, co samo w sobie mowi wszystko. Zywi krupierzy, czasem zlapiesz polski stol, te wszystkie teleturnieje typu Crazy Time wieczorem ciezko usiasc. Jedno co mnie wkurza — przy slabszym laczu potrafi sie zaciac, no ale to juz nie ich problem pewnie.

    Startowy bonus w 888starz to 100% do jakichs 1500 zl plus 150 free spinow, podzielone na pare pierwszych wplat. Obrot x35 i powiem wprost — to trzeba odrobic. Dostalem kiedys kilkadziesiat spinow bez wplaty za sama rejestracje, z czego nic wielkiego nie wyszlo. Biezace oferty zobaczysz pod 888starz apk mod jesli komus sie chce grzebac. Wplacic mozna od okolo 20 zl, konto zakladasz w chwile, z tym ze dokumenty warto wrzucic na starcie.

    Wyplaty ida raczej szybko. Skrill i Neteller mam w kilka godzin, Visa/Mastercard wolniej, do trzech dni. Platnosci krypto sa najwygodniejsze — BTC mialem na portfelu w pol godziny. Czat w 888starz dziala po polsku, czat na zywo, srednio kilka minut czekania, z tym ze raz dostalem czyste kopiuj-wklej.

    Na telefonie gram najczesciej — mobilka chodzi bez zarzutu, ale jest tez 888starz apk do pobrania. Zainstalowalem, glownie dla powiadomien, nie zawiesza sie. Ostrzezenie — po sieci krazy cos w stylu 888starz apk mod, omijajcie szerokim lukiem, sciagajcie tylko z oficjalnego zrodla. Dzialaja na licencji Curacao — wiadomo, nie polska, kazdy sam ocenia czy mu to pasuje.

  7. 2026-09-04 12:09:24
    回复

    Мы осознали: без стационара нам не обойтись. И каждый раз становилось только хуже. Тогда мы решились на стационарное лечение в Санкт-Петербурге. стационарная наркологическая помощь — это было единственное, что реально помогло. Он находился под наблюдением 24 часа в сутки. Мы снова могли разговаривать, не боясь его срывов. выведение из запоя санкт петербург стационар выведение из запоя санкт петербург стационар Это может спасти жизнь для нашего города. Не ждите, пока станет поздно. Вывод из запоя в стационаре — это реальное решение проблемы!

  8. 2026-09-04 12:09:58
    回复

    Such writing is increasingly rare and worth supporting through attention, and a stop at labelandship extended that supportive attention across more pages, the conscious choice to spend time on sites that produce careful work rather than convenient consumption is itself a small form of patronage and this site is receiving that conscious patronage from me.

  9. 2026-09-04 12:09:48
    回复

    Even from a single post the editorial care is clear, and a stop at marinermerchant extended that care across more pages, the kind of attention to quality that shows up in every paragraph is what separates serious sites from the rest and this one has clearly invested in that paragraph level attention across what I have read.

  10. 2026-09-04 12:09:29
    回复

    A well calibrated piece that knew its scope and stayed inside it, and a look at embroideryemporium maintained the same scope discipline, scope creep is one of the failure modes of long blog posts and this site has clearly invested in the editorial discipline to prevent it which shows up in tightly contained pieces.

  11. 2026-09-04 13:09:08
    回复

    Closed it feeling I had taken something away rather than just consumed something, and a stop at blog33reflect extended that taking away feeling, the difference between content I extract value from and content I just pass through is something I track informally and this site is consistently in the value extraction column for me.

  12. 2026-09-04 14:09:57
    回复

    Reading this gave me the rare experience of fully agreeing with all the conclusions, and a stop at metricmeadow continued that agreement pattern, content that aligns with my existing views without seeming designed to do so is just content that happens to be reasonable and this site reads as reasonable rather than ideological mostly.

  13. 2026-09-04 14:09:24
    回复

    Even just sampling a few posts the consistency is what stands out, and a look at silverstride confirmed the broader pattern, sites where every piece I sample lives up to the standard set by the others are sites with serious quality control and this one has clearly invested in whatever editorial process produces that consistency reliably.

  14. fiery_zePr
    2026-09-04 14:09:16
    回复

    Ogrywam sie tam od jakichs pieciu miesiecy, no to chyba moge cos napisac. Trafilem tam z polecenia kolegi, bo szukalem czegos gdzie sloty laduja sie normalnie. Wybor slotow robi wrazenie — gdzies kolo 3500 pozycji, co prawda i tak grywam glownie na kilku. Pragmatic Play, Play'n GO i NetEnt maja tam najwiecej swojego, nie brakuje takich rzeczy jak Gates of Olympus, Sweet Bonanza i Book of Dead.

    Na start w Fiery Play daja doplata 100% do 1500 zl i do tego 200 spinow gratis, wydawanych po kilka dni. Obrot to x30, co jest w miare uczciwe, tyle ze warto przeczytac warunki — max bet w trakcie odgrywania jest ograniczony o czym nikt nie krzyczy. Dorzucali tez kod bez depozytu na 50 spinow, ale to chyba akcja czasowa. Aktualne promki mozecie sprawdzic na fier play zanim sie zarejestrujecie.

    Cala rejestracja to doslownie chwila, najnizsza wplata zaczyna sie od 40 zl. Zwykle ide karta, czasem Neteller, wyjscia z kasa robilem pare razy — raz zeszlo pol dnia, jeden raz przeciagnelo sie do prawie trzy dni, przez KYC. Bitcoin tez obsluguja i podobno tam idzie najszybciej.

    Wieczorami siedze glownie na zywo — stoly od Evolution, czesc krupierow mowi po polsku, co sie rzadko trafia. Crazy Time leci non stop, choc ja tam bardziej ogladam niz gram. Stoly blackjacka sa w kilkunastu wariantach.

    Gram glownie z komorki, przegladarkowo i dziala to plynnie, choc na wolniejszym necie transmisja lubi sie ciac. Dzialaja na licencji Curacao, wiec bez cudow — ale wyplacili, wiec nie narzekam. Obsluga w Fiery Play odpowiada po polsku i to zywy czlowiek, nie bot. Najbardziej denerwuje mnie to te powiadomienia mailowe — wylaczylem w ustawieniach i spokoj.

  15. 2026-09-04 14:09:04
    回复

    Better than the average post on this subject by some distance, and a look at layoutlounge reinforced that, you can tell within the first paragraph that the writer here actually cares about the topic rather than just covering it for the sake of having something to publish that week or that day.

  16. 2026-09-04 15:09:31
    回复

    A clear cut above the usual noise on the subject, and a look at movievault only made that gap wider in my view, the kind of place that earns its visitors through quality rather than through aggressive marketing or sponsored placements which is increasingly the only way most sites stay afloat across the modern web.

  17. 2026-09-04 15:09:27
    回复

    Now planning to come back when I have the right kind of attention to read carefully, and a stop at auditamber reinforced that plan, choosing the right moment to read certain content is a quiet form of respect for the work and this site is generating those careful planning behaviours from me consistently as a reader.

  18. 2026-09-04 15:09:53
    回复

    Мы — один из лучших хостингов игровых серверов.
    У нас гарантирована работа вашего сервера круглосуточно,
    мы предоставляем надёжную защиту уровней L3-L7,
    а также мы используем только качественное и современное оборудование.
    https://lix.li/qPLFLj

  19. 2026-09-04 15:09:38
    回复

    Generally my comment to other readers about new sites is to wait and see but for this one I would jump to recommend now, and a look at bandwidthbarn reinforced that early recommendation, the speed at which a site earns my recommendation is itself a quality signal and this one has earned mine quickly clearly.

  20. 2026-09-04 18:09:01
    回复

    Now recognising the specific pleasure of reading writing that shows real care for sentence shapes, and a look at patchportal extended that craft pleasure, sentence level writing quality is something most blog content ignores entirely and this site has clearly invested in the prose layer alongside the substance which is rare today.